#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define nn "\n";
#define pb push_back
const int N = 1e6 + 8 , inf = 1e17 ;
int n , m , q , a[N], b[N];
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin>> n ;
vector<pair<int, int >> v ;
for(int i = 1; i <= n; i++){
cin>> a[i]>> b[i];
v.pb({a[i] , b[i]});
}
if(n == 1 ){
cout << b[1];
return 0 ;
}
sort(v.begin() , v.end());
int mx =-inf , pos =0 ;
for(int i =0 ; i < v.size() ; i++){
if(v[i].second - v[i].first>= mx ){
mx = v[i].second - v[i].first;
pos = i ;
}
if(v[i].second - v[i].first >= 0 ){
mx = v[i].second - v[i].first;
pos = i ;
break;
}
}
int S = v[pos].second , mn = v[pos].first ;
mx =0 ;
for(int i = pos+1 ; i < v.size() ; i++){
mx = max(mx , S + v[i].second - (v[i].first - mn) );
S+=v[i].second;
}
cout << mx ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |