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>
#define lop(i,a,b) for(ll i = a; i < b; i++)
#define alop(i,v) for(auto i: v)
#define ll long long
#define all(v) v.begin(),v.end()
#define pb push_back
using namespace std;
int main(){
ll n, t1, t2; cin >> n;
ll arr[n];
vector<pair<ll,ll>> v, m;
lop(i,0,n){
cin >> t1 >> t2;
v.pb({t1,t2});
}
sort(all(v));
int i = 0;
alop(it,v){
if(i == 0) arr[0] = it.second;
else arr[i] = it.second + arr[i-1];
i++;
}
ll mx = -1e18;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i+j >= n) break;
ll sum = arr[i+j];
if(j == 0) mx = max(mx, sum - arr[i+j-1]);
else{
if(i != 0) sum -= arr[i-1];
mx = max(mx, sum - (v[i+j].first - v[i].first));
}
}
}
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... |