/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 2ms 532.0 KiB
#3 Wrong Answer 2ms 532.0 KiB

Code

#include<bits/stdc++.h>
#define ll          long long
#define nl          '\n'
#define F           first
#define S           second
#define pb          push_back
#define all(a)      (a.begin()),(a.end())
#define Input       freopen("in.txt","r",stdin)
#define Output      freopen("out.txt","w",stdout)
#define PI          2*acos(0.0)
#define MOD         1000000007
using namespace std;


const int N = 2e5 + 5;

int n, a[N];

void Solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    int ans = 0, ext = 0;
    for (int i = n; i >= 1; i--)
    {
        if (a[i] <= i + ext)
        {
            ans += a[i];
            a[i]--;
            int x = min(ext, a[i]);
            ext -= x;
            a[i] -= x;
            i -= a[i];
        }
        else
            ext++;
    }
    cout << ans << nl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t, T = 1;
    cin >> T;
    for (t = 1; t <= T; t++)
        Solve();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1234 E. Roy and Maximum Removals
Contest
Happy New Year 2026
Language
C++17 (G++ 13.2.0)
Submit At
2026-01-06 15:15:05
Judged At
2026-01-06 15:15:05
Judged By
Score
0
Total Time
2ms
Peak Memory
532.0 KiB