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;
void solve(){
int n, k;cin >> n >> k;
long long ans = 0;
pair<int, int> a[n];for(int i = 0;i < n;i++) cin >> a[i].first >> a[i].second;
sort(a, a+n);
int m=a[0].second, mx = INT_MAX, x = -1, d = 1, dx = 0;
for(int i = 1;i < n && a[i].first == a[0].first;i++){
a[i].first++;
ans += k;
}
for(int i = 1;i < n;i++){
if(a[i].first!=x){
d+=dx;
x = a[i].first;
m = min(m, mx);
dx = 1;
mx = a[i].second;
} else {
mx = min(mx, a[i].second);
dx++;
}
if(d) d--;
else ans += m;
}
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
# | 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... |