#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define bitcount __builtin_popcountll
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<long long,null_type,less_equal<>,rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
struct node {
int sum, suff;
friend node operator+ (node l, node r) {
return {
l.sum + r.sum,
max(r.suff, l.suff + r.sum)
};
}
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n; cin >> n;
pair<int,int> a[n];
for (int i = 0; i < n; cin >> a[i].first >> a[i++].second);
sort(a, a + n);
long long sum = 0, pref = 0, ans = (*max_element(a, a + n)).second;
for (int i = 1; i < n; i++) {
pref = min(pref, sum - a[i].second);
sum += a[i].first;
ans = max(ans, a[i].second - a[i].first - pref);
}
cout << ans;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:27:52: warning: operation on 'i' may be undefined [-Wsequence-point]
27 | for (int i = 0; i < n; cin >> a[i].first >> a[i++].second);
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |