[CodeForces] [610B] Vika and Squares

Problem Description

Loading...

Problem Analysis

The idea is that first there are at least
the smallest kind *n times (mind the data range)
then the rest is divided by the smallest one
into several parts
take the size of the largest part and add it to the result
(the first and last parts can be treated as the same group)

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
29
30
31
32
33
34
35
36
37
38
39
40
#include<stdio.h>
int a[200200];
int main() {
	int n;
	while(scanf("%d",&n)!=EOF) {
		scanf("%d",&a[0]);
		int min=a[0];
		for(int i=1; i<n; i++) {
			scanf("%d",&a[i]);
			if(min>a[i])
				min=a[i];
		}
		__int64 res=(__int64)min*(__int64)n;
		int t=0;
		int tres=0;
		int maxtres=0;
		int firt=0;
		bool flag=false;
		for(int i=0; i<n; i++) {
			a[i]-=min;
			if(a[i]!=0) {
				if(flag) {
					tres++;
				} else {
					firt++;
				}
			} else {
				flag=true;
				if(maxtres<tres)
					maxtres=tres;
				tres=0;
			}
		}
		tres+=firt;
		if(maxtres<tres)
			maxtres=tres;
		printf("%I64d\n",res+(__int64)maxtres);
	}
	return 0;
}

Problem address: 【CodeForces】[610B]Vika and Squares

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...