#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int maxn = (int)1e6+5;
const int maxv = (int)5e6+5;
struct Event {
int x, type, val;
Event () {}
Event (int _x, int _c, int _d): x(_x), type(_c), val(_d) {}
};
int n;
vector<Event> events;
priority_queue<pair<int,int>> pq;
long long ans = 0;
bool cmp (Event a, Event b) {
return (a.x < b.x);
}
int main () {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1;i <= n; i++) {
int x, y;
cin >> x >> y;
events.push_back(Event(-x/2+1, 1, y));
events.push_back(Event(x/2+1, -1, y));
}
sort (events.begin(), events.end(), cmp);
for (int i = 0;i+1 < (int)events.size(); i++) {
if (events[i].type == -1) {
while ((int)pq.size() && pq.top().se < events[i].x) pq.pop();
}
else if (events[i].type == 1) {
int r = -(events[i].x-1);
pq.push({events[i].val, r});
}
if ((int)pq.size()) {
ans += 1LL * pq.top().fi * (events[i+1].x - events[i].x);
}
}
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... |