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 ll long long
#define ld long double
#define debug if(0)
const int mod = 1e9 + 7;
const ll infL = 1e18 + 7;
const int inf = 1e9 + 7;
void add(int &a, int b) { a = (a+b)%mod; }
int add(int a, int b, int c) { int res = (((a+b)%mod) + c)%mod; return res; }
const int M = 1e5 + 4;
ll cnt[M];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
vector<int> h(n), k(n);
for(int i=0; i<n; i++) {
cin>>h[i]>>k[i];
}
for(int i=0; i<n; i++) {
set<pair<int, int>> S;
for(int j=1; j<=h[i]; j++) {
S.insert({cnt[j], j});
}
for(int j=0; j<k[i]; j++) {
pair<int, int> p = *S.begin();
S.erase(S.begin());
cnt[p.second]++;
}
}
ll ans = 0;
for(int i=1; i<M; i++) {
ans += ((cnt[i]*(cnt[i]-1))/2);
}
cout<<ans;
}
# | 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... |