#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
using namespace std;
const int N=5e5+5;
const int inf=1e18;
const int mod=1e9+7;
const int N1=1e5+25;
vector<pair<int,int> >v;
vector<int>v1;
int dp[N];
int dp1[N];
struct edge{
int v,time;
};
signed main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
boost;
int n;
cin>>n;
v.push_back({0,0});
int ans=-inf;
for(int i=0;i<n;i++){
int x,y;
cin>>x>>y;
ans=max(ans,y);
v.push_back({x,y});
dp1[i+1]=dp1[i]+y;
}
sort(v.begin(),v.end());
int cnt=0;
for(int i=1;i<=n;i++){
cnt+=v[i].second;
dp[i]=cnt-v[i].first;
}
cnt=v[1].first;
int pos=1;
for(int i=2;i<=n;i++){
ans=max(ans,dp[i]+cnt);
if(cnt>dp1[i-1]+v[i].first){
cnt=dp1[i-1]+v[i].first;
}
}
cout<<ans;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:39:9: warning: unused variable 'pos' [-Wunused-variable]
39 | int pos=1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |