QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201157 | #7342. Waiter's Problem | kjhhjki | AC ✓ | 74ms | 3824kb | C++20 | 715b | 2023-10-05 12:47:55 | 2023-10-05 12:47:55 |
Judging History
answer
#include <bits/stdc++.h>
#define MAXN 100005
#define For(I,A,B) for(int I = (A), endi = (B); I <= endi; ++I)
#define foR(I,A,B) for(int I = (A), endi = (B); I >= endi; --I)
#define ForE(I,A) for(int I = head[A]; I; I = e[I].nxt)
using namespace std;
typedef long long _ll;
typedef unsigned int ui;
int T,n,a[MAXN];
_ll sum,ans;
void solve()
{
cin >> n; ans = sum = 0;
For(i,1,n) cin >> a[i];
sort(a+1,a+n+1,greater<int>());
For(i,1,n)
{
sum += a[i];
ans = max(ans, sum-1ll*i*(i-1)/2);
}
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3372kb
input:
1 6 0 9 9 1 7 5
output:
24
result:
ok 1 number(s): "24"
Test #2:
score: 0
Accepted
time: 74ms
memory: 3824kb
input:
10007 2 6 2 5 2 3 2 10 6 2 5 0 2 1 7 6 2 4 4 2 1 5 8 6 10 1 8 0 10 9 0 3 10 5 5 10 4 9 9 5 5 2 6 7 9 4 1 7 2 0 0 7 9 4 4 6 1 8 2 10 6 6 8 6 4 4 7 2 1 8 9 7 4 9 8 3 0 2 0 10 4 1 4 9 4 2 2 5 3 5 1 3 10 4 1 6 5 3 8 6 3 2 3 10 0 0 2 9 2 1 10 6 8 6 9 2 4 1 4 2 8 5 3 0 2 4 10 9 2 7 9 2 7 3 9 5 2 5 3 5 5 9...
output:
7 16 5 7 10 33 17 30 7 0 21 26 28 14 6 7 19 29 15 13 27 16 15 32 7 21 6 25 9 29 27 13 29 13 22 24 24 13 22 22 6 23 26 5 3 9 41 8 21 30 7 37 40 20 2 14 5 26 25 21 23 15 1 16 4 19 16 7 26 13 11 6 7 41 21 15 27 16 33 33 24 22 23 12 17 18 16 8 30 21 21 15 10 17 29 16 6 22 25 16 1 7 30 28 30 20 18 27 24 ...
result:
ok 10007 numbers