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 <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <stack>
#include <unordered_map>
using namespace std;
typedef long long ll;
struct dzielo {
ll s;
ll v;
};
struct triple {
ll a;
ll b;
ll c;
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n; cin >> n;
vector<dzielo> arts(n);
for(ll i = 0; i < n; i++) {
ll s, v; cin >> s >> v;
arts[i].s = s; arts[i].v = v;
}
sort(arts.begin(), arts.end(), [](dzielo a, dzielo b) {return a.s < b.s;});
ll l = arts[0].s, p = arts[0].s;
ll s = arts[0].v;
ll mx = s - p + l;
for(ll i = 1; i < n; i++) {
l = min(l, arts[i].s);
p = max(p, arts[i].s);
s+=arts[i].v;
mx = max(mx, s - p + l);
//cout << l << " " << p << " " << s << endl;
}
cout << mx;
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... |