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 11:55:42
Task:Cent saving
Sender:Ace of Spades
Submission time:2016-05-28 11:55:42
Status:READY
Result:ACCEPTED

Show test data

Code

#include<bits/stdc++.h>

using namespace std;

int main(void) {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int64_t t;
    cin >> t;
    for(;t>0;t--) {
        int64_t n;
        cin >> n;
        int64_t total=0, p0=0, p1=0, p2=0, m2=0, m1=0;
        for(int64_t i=0;i<n;i++) {
            int64_t p;
            cin >> p;
            if(p%5 == 0) p0++;
            if(p%5 == 1) p1++;
            if(p%5 == 2) p2++;
            if(p%5 == 3) m2++;
            if(p%5 == 4) m1++; 
            total+=p;
        }

        total-=2*p2;
        total-=p1;
        if(m2 >= m1) {
            m2-=m1;
            total-=2*m1;
            total-=m2/2;
            if(m2%2 == 1) total+=2;
        } else {
            m1-=m2;
            total-=2*m2;
            total-=2*(m1/3);
            if(m1%3 == 1) {
                total++;
            } else if(m1%3 == 2) {
                total+=2;
            }
        }
        cout << total << '\n';
    }

    return 0;
}