# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
440056 | gromperen | Unija (COCI17_unija) | C++14 | 372 ms | 31464 KiB |
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
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<pair<int,int>> v(n), a;
ll ans = 0;
for (int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second;
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
int prev = 0, prevy = 0;
for (int i = 0; i < n; ++i) {
if (v[i].first == prev ) continue;
if (v[i].second <= prevy) continue;
a.push_back(v[i]);
prev = v[i].first;
prevy = v[i].second;
}
for (int i = 0; i < a.size(); ++i) {
ans += a[i].second * (a[i].first - ((i < a.size() - 1) ? a[i+1].first : 0));
}
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |