CSES - Practice Contest 2024 - Results
Submission details
Task:Cent saving
Sender:asdf
Submission time:2024-09-28 13:11:48 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.02 sdetails
#20.02 sdetails

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 1e5 + 5;

int n, p[N];
int cnt[10];

void solve() {
    cin >> n;
    memset(cnt, 0, sizeof cnt);
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        sum += p[i];
        p[i] %= 5;
        cnt[p[i]]++;
    }

    int ans = 0;
    // connect 4 & 9 first

    int take = min(cnt[3], cnt[4]);
    ans += take * 2;
    cnt[3] -= take;
    cnt[4] -= take;

    ans += (cnt[3] / 2);
    ans += (cnt[4] / 3) * 2;
    ans += cnt[1];
    ans += cnt[2] * 2;

    cout << sum - ans << '\n';
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);

    int t;
    cin >> t;

    while (t--) {
        solve();
    }
}

Test details

Test 1

Verdict:

input
100
1000
528433894 255789530 559301042 ...

correct output
475191144965
460688647850
478543444030
475238936090
456736521510
...

user output
475191144964
460688647850
478543444028
475238936090
456736521510
...
Truncated

Test 2

Verdict:

input
1
100000
666086355 190481330 514353517 ...

correct output
47176864928795

user output
47176864928793