CSES - Practice Contest 2024 - Results
Submission details
Task:Cent saving
Sender:\(._.)/
Submission time:2024-09-28 14:33:23 +0300
Language:C++ (C++11)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.05 sdetails

Code

// Online C++ compiler to run C++ program online
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    int t;
    cin >> t;
    
    for (int test = 0; test < t; test++)
    {
        int n;
        cin >> n;
        
        long long sum = 0;
        long long a1 = 0;
        long long a2 = 0;
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            sum += (x/5)*5;
            x = x % 5;
        
            if (x == 3)
                a2 += 1;
            if (x == 4)
                a1 += 1;
        }
    
        
        long long a = min(a1, a2);
        sum += a * 5;
        a1 -= a;
        a2 -= a;
        sum += (a2 / 2) * 5;
        a2 = a2 % 2;
        sum += (a1 / 3) * 10;
        a1 = a1 % 3;
    
        if (a2 == 0 or a1 == 0)
            sum += (a1 + a2) * 5;
        else
            sum += ( (a1 * 3 + a2 * 4) / 5 ) * 5;
    
        cout << sum << endl;
    }
    

    return 0;
}

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

Test 2

Verdict: ACCEPTED

input
1
100000
666086355 190481330 514353517 ...

correct output
47176864928795

user output
47176864928795