#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
const int maxn = 1e5 + 20;
pair<int, int> a[maxn];
vector<pair<int, int>> q;
void add(int val, int cnt) {
if (!cnt) {
return;
}
if (!q.empty() && q.back().first == val) {
q.back().second += cnt;
}
else {
q.emplace_back(val, cnt);
}
}
void just_do_it() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
add(0, a[i].first - a[i - 1].first);
vector<pair<int, int>> nxt;
while (a[i].second) {
if (q.back().second >= a[i].second) {
nxt.emplace_back(q.back().first, q.back().second - a[i].second);
nxt.emplace_back(q.back().first + 1, a[i].second);
a[i].second = 0;
}
else {
nxt.emplace_back(q.back().first + 1, q.back().second);
a[i].second -= q.back().second;
}
q.pop_back();
}
reverse(nxt.begin(), nxt.end());
for (auto p: nxt) {
add(p.first, p.second);
}
}
long long res = 0;
for (auto p: q) {
res += 1LL * p.first * (p.first - 1) / 2 * p.second;
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
412 KB |
Output is correct |
2 |
Correct |
289 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1053 ms |
996 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1062 ms |
996 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1063 ms |
996 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
1320 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1080 ms |
1364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |