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 all(x) x.begin(), x.end()
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
int n;
cin >> n;
vector<pair<long long , int> > a;
for (int i = 0; i < n; i++) {
long long u;
int v;
cin >> u >> v;
a.push_back({u , v});
}
sort(all(a));
long long ans = 0LL;
for (int i = 0; i < n; i++) {
long long sum = 0 , mx = 0 , mn = 1e9;
for (int j = i; j < n; j++) {
sum += a[j].second;
mx = max(mx , a[j].first);
mn = min(mn , a[j].first);
//cout << "cur ans " << sum - (mx - mn) << '\n';
//cout << "Mx " << mx << " " << mn << " " << sum << '\n';
//cout << "seg " << i + 1 << " " << j + 1 << '\n' << '\n';
ans = max(ans , sum - (mx - mn));
}
}
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... |