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(int 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;});
vector<ll> sp(n + 1);
for(int i = 0; i < n; i++) {
sp[i + 1] = sp[i] + arts[i].v;
}
// vector<triple> diff(n - 1);
// for(int i = 0; i < n - 1; i++) {
// diff[i].a = arts[i + 1].s - arts[i].s;
// diff[i].b = i;
// diff[i].c = arts[i + 1].v + arts[i].v;
// }
ll mx = 0;
for(int i = 0; i < n; i++) {
dzielo d = arts[i];
for(int j = i; j < n; j++) {
dzielo o = arts[j];
mx = max(mx, sp[j + 1] - sp[i] - o.s + d.s);
//cout << d.s << " " << d.v << " dsv " << o.s << " " << o.v << " osv " << i << " " << j << " ij " << sp[j + 1] << " " << sp[i] << endl;
//cout << sp[j + 1] - sp[i] - o.s + d.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... |