CSES - HIIT Open 2016 - Results
Submission details
Task:Cent saving
Sender:LTR
Submission time:2016-05-28 12:47:23 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.08 sdetails
#20.09 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;
			}
		}

		int threefourredux = std::min(threes, fours);
		cost += threefourredux * 5;
		threes -= threefourredux;
		fours -= threefourredux;

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

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

Test details

Test 1

Verdict:

input
100
1000
528433894 255789530 559301042 ...

correct output
475191144965
460688647850
478543444030
475238936090
456736521510
...

user output
475191144905
460688647800
478543443970
475238936090
456736521470
...

Test 2

Verdict:

input
1
100000
666086355 190481330 514353517 ...

correct output
47176864928795

user output
47176864927935