[CodeForces] [651B] Beautiful Paintings

Problem Description

Loading...

Problem Analysis

At first I thought it was just a simple sort
Then I realized that after rearranging
as long as
a[i+1]>a[i], we increment cnt
so the optimal arrangement can be
something like 12312312323333

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<stdio.h>
#include<string.h>
int a[1020];
int main() {
	int n;
	while(scanf("%d",&n)!=EOF) {
		int cnt=0;
		memset(a,0,sizeof(a));
		for(int i=0; i<n; i++) {
			int t;
			scanf("%d",&t);
			a[t]++;
		}
		int res=0;
		while(n) {
			for(int i=1; i<1020; i++) {
				if(a[i]) {
					res++;
					n--;
					a[i]--;
				}
			}
			res--;
		}
		printf("%d\n",res);
	}
	return 0;
}

Problem link: 【CodeForces】[651B]Beautiful Paintings

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...