Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 12:13:37
2016-05-28 12:10:28
Task:Cent saving
Sender:Barely Div 1
Submission time:2016-05-28 12:13:37
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>

using namespace std;

int main() {
	int t, n;
	cin >> t;

	for(int i=0; i<t; i++) {
		cin >> n;
		long long sum=0, p;
		long long save=0, m3=0, m4=0;
		for(int j=0; j<n; j++) {
			cin >> p;
			sum += p;
			switch(p%5) {
				case 0: break;
				case 1: save++; break;
				case 2: save+=2; break;
				case 3: m3++; break;
				case 4: m4++; break;
			}
		}
		int c34 = min(m3, m4);
		save += 2*c34;
		m3 -= c34;
		m4 -= c34;
		save += m3/2;
		save -= 2*(m3&1);
		save += 2*(m4/3);
		save -= m4%3;
		cout << sum-save << endl;
	}

	return 0;
}