This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n,h,k,sum,cnt[100002],a[100001];
long long res;
int main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n;
cnt[1]=n;
while (n--){
cin >> h >> k;
cnt[h+1]--;
sum+=k;
}
for (int i=1;i<=100001;i++){
cnt[i]+=cnt[i-1];
if (!a[cnt[i]])
a[cnt[i]]=i;
}
for (int i=1;i<=100000;i++)
if (!a[i])
a[i]=a[i-1];
for (int i=100000;i>=1;i--)
cnt[i]+=cnt[i+1];
for (int i=1;i<=100000;i++){
int l=0,r=100000,kq=-1;
while (l<=r){
int mid=(l+r)>>1;
if (cnt[max(a[mid],i)]+mid*max(a[mid]-i,0)>=sum){
kq=mid;
r=mid-1;
}
else
l=mid+1;
}
sum-=kq;
res+=kq*(kq-1)/2;
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |