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;
#define int long long
const int INF = 1e16;
signed main(){
ios::sync_with_stdio(false), cin.tie(0);
int n; cin >> n;
int a[n], b[n], mx = 0;
for(int i = 0; i < n; i++) cin >> a[i] >> b[i], mx = max(mx, a[i]);
int pre[mx + 1]{};
for(int i = 0; i < n; i++){
pre[0]++, pre[a[i] + 1]--;
}
for(int i = 1; i <= mx; i++) pre[i] += pre[i - 1];
int ans = 0, cnt = accumulate(b, b + n, 0);
ans -= cnt;
for(int i = mx; i > 0; i--){
int cur = min(pre[i], cnt / i);
ans += cur * cur;
cnt -= cur;
}
cout << ans / 2;
}
# | 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... |