CSES - HIIT Open 2016 - Results
Submission details
Task:Cent saving
Sender:LTR
Submission time:2016-05-28 12:53:23 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.09 sdetails
#2ACCEPTED0.08 sdetails

Code

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>

int main()
{
	int t;
	std::cin >> t;
	for (int ti = 0; ti < t; ++ti) {
		int n;
		std::cin >> n;

		long long cost = 0;
		int threes = 0;
		int fours = 0;
		for (int ni = 0; ni < n; ++ni) {
			long long p;
			std::cin >> p;
			long long m = p % 5;
			switch (m) {
				case 0:
				case 1:
				case 2:
					cost += (p - m);
					break;
				case 3:
					cost += (p - m);
					threes++;
					break;
				case 4:
					cost += (p - m);
					fours++;
					break;
			}
		}

		// Prefer 3 + 4
		int combos = std::min(threes, fours);
		cost += combos * 5;
		threes -= combos;
		fours -= combos;

		// Sum remaining 3
		if (threes > 0) {
			int m = threes % 2;
			int combines = ((threes - m) / 2);
			cost += (combines + m) * 5;
		}

		// sum remaining 4
		if (fours > 0) {
			int m = fours % 3;
			int combines = ((fours - m) / 3);
			cost += ((2 *combines) + m) * 5;
		}

		std::cout << cost << std::endl;
	}
}

Test details

Test 1

Verdict: ACCEPTED

input
100
1000
528433894 255789530 559301042 ...

correct output
475191144965
460688647850
478543444030
475238936090
456736521510
...

user output
475191144965
460688647850
478543444030
475238936090
456736521510
...

Test 2

Verdict: ACCEPTED

input
1
100000
666086355 190481330 514353517 ...

correct output
47176864928795

user output
47176864928795