#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,h,k,sum[100002],cnt[100002],res,cur,mx;
int32_t main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n;
cnt[1]=n;
while (n--){
cin >> h >> k;
mx=max(mx,h);
cnt[h+1]--;
sum[h-k+1]++;
sum[h+1]--;
cur+=k;
}
for (int i=1;i<=100001;i++){
cnt[i]+=cnt[i-1];
sum[i]+=sum[i-1];
}
for (int i=100000;i>=1;i--)
sum[i]+=sum[i+1];
for (int i=1;i<=mx;i++){
if (!cur)
break;
int l=0,r=cnt[i],kq=-1;
while (l<=r){
int mid=(l+r)>>1,amount=0;
for (int j=mx;j>=i;j--)
amount=min(amount+mid,sum[j]);
if (amount>=cur){
kq=mid;
r=mid-1;
}
else
l=mid+1;
}
cur-=kq;
res+=1LL*kq*(kq-1)/2;
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
3 ms |
1880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
2000 KB |
Output is correct |
2 |
Execution timed out |
1036 ms |
1880 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1012 ms |
1880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1034 ms |
1880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1028 ms |
1880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1039 ms |
1880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1038 ms |
1880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1042 ms |
1880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |