#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 500100;
map<ll, ll> sum;
vector<pair<ll, ll> > values;
vector<ll> pref;
ll n, x, y;
ll get_val(int l, int r) {
ll sum =1LL* pref[r] - pref[l-1];
ll diff = values[r].first - values[l].first;
return sum - diff;
}
int main() {
cin>>n;
for(int i=0;i<n;i++) {
cin>>x>>y;
sum[x] += y;
}
values.pb(mp(0LL,0LL));
pref.pb(0LL);
for(auto i:sum) {
values.pb(mp(i.first, i.second));
pref.pb(pref.back() + i.second);
}
ll l = 1LL;
ll result = get_val(1,1);
ll max_pref = values[1].first;
for(ll i=2;i<values.size();i++) {
ll curr_val = pref[i] - values[i].first + max_pref;
result = max(result, curr_val);
max_pref = max(max_pref, values[i].first - pref[i-1]);
}
cout<<result;
return 0;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:35:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ll i=2;i<values.size();i++) {
~^~~~~~~~~~~~~~
art.cpp:32:8: warning: unused variable 'l' [-Wunused-variable]
ll l = 1LL;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |