CSES - Practice Contest 2024 - Results
Submission details
Task:Cent saving
Sender:asdf
Submission time:2024-09-28 14:16:42 +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 res = 0;
    // int take = min(cnt[3], cnt[4]);

    // for (int t = 0; t <= take; t++) {
    //     int ans = 0;
    //     ans += take * 2;

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

    //     ans += cnt[1];
    //     ans += cnt[2] * 2;
    //     res = max(res, ans);
    // }

    // int take = min(cnt[3], cnt[4]);
    int take = cnt[4] / 3;

    for (int t = 0; t <= take; t++) {
        int ans = 0;
        ans += take * 2; // 4 4 4

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

        ans += cnt[1];
        ans += cnt[2] * 2;
        res = max(res, ans);
    }


    cout << sum - res << '\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
475191145115
460688647990
478543444193
475238936245
456736521675
...
Truncated

Test 2

Verdict:

input
1
100000
666086355 190481330 514353517 ...

correct output
47176864928795

user output
47176864945440