CSES - HIIT Open 2016 - Results
Submission details
Task:Cent saving
Sender:ContinuedLife
Submission time:2016-05-28 14:46:10 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.06 sdetails
#20.07 sdetails

Code

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(6);

using namespace std;

bool mycomp(int a, int b){
	return a > b;
}

int main(){ _
	int TC;	cin >> TC;
	while(TC--){
		int n,sum = 0;	cin >> n;
		vector<int> vi(n, 0);
		for(int i = 0; i < n; ++i){
			cin >> vi[i];
			sum += vi[i];
			vi[i] %= 5;
			switch(vi[i]){
				case 0:	vi[i] = 0;	break;
				case 1:	vi[i] = -1;	break;
				case 2:	vi[i] = -2;	break;
				case 3:	vi[i] = 2;	break;
				case 4:	vi[i] = 1;	break;
			}
		}

		sort(vi.begin(), vi.end(), mycomp);
//		for(int i = 0; i < vi.size(); ++i)	cout << vi[i] << " ";
//		cout << endl;
		int save = 0, temp = 0;
		for(int i = 0; i < n; ++i){
			if(vi[i] <= 0){
				if(temp > 0){	save += temp;	temp = 0;}
				save += vi[i];
			}else{
				temp += vi[i];
				switch(temp){
					case 2:	temp = 2;	break;	
					case 3:	temp = -2;	break;
					case 4:	temp = -1;	break;
				}
				if(temp < 0){
					save += temp;
					temp = 0;
				}
			}
		}

		cout << sum + save << endl;
	}
	return 0;
}

Test details

Test 1

Verdict:

input
100
1000
528433894 255789530 559301042 ...

correct output
475191144965
460688647850
478543444030
475238936090
456736521510
...

user output
-1550224741
1127147323
1802074339
-1502433611
1469988304
...
Truncated

Test 2

Verdict:

input
1
100000
666086355 190481330 514353517 ...

correct output
47176864928795

user output
944166176