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 FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef long long ll;
const int MAXN = 100100;
int n;
vii seq;
ll cnt[MAXN];
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
vector<pair<ll, int>> rem;
int main()
{
FAST_IO;
cin >> n;
REP(n) {
int h, k; cin >> h >> k;
seq.pb({h, k});
}
sort(seq.begin(), seq.end());
ll ans = 0;
FOR(i, 0, n-1) {
int lst = i==0 ? 0 : seq[i-1].f;
int h = seq[i].f;
int k = seq[i].s;
FOR(j, lst+1, h) {
q.push({0, j});
}
rem.clear();
REP(k) {
auto pp = q.top();
q.pop();
int j = pp.s;
cnt[j]++;
rem.pb({cnt[j], j});
}
for (auto pp : rem) q.push(pp);
lst = h;
}
FOR(i, 0, MAXN-1) {
if (cnt[i] == 0) continue;
ans += (cnt[i] * (cnt[i]-1))/2;
}
cout << ans << "\n";
return 0;
}
# | 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... |