#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <functional>
#include <iomanip>
#include <sstream>
#include <numeric>
#define int long long
#define pb push_back
#define be begin()
#define en end()
#define fi first
#define se second
#define makep make_pair
#define nn int n; cin>>n
#define mm int m; cin>>m
#define kk int k; cin>>k
using namespace std;
int mod=1e9+7;
void ai(vector<int> &v){
for(auto &go : v){
cin>>go;
}
}
void yesno(int k){
if(k==1){
cout<<"Yes";
}
else{
cout<<"No";
}
}
void solve(){
nn;
vector<pair<int,int>> arr(n);
vector<int> pre(n+1,0);
for(int i=0;i<n;i++){
cin>>arr[i].first;
cin>>arr[i].second;
}
sort(arr.be,arr.en);
for(int i=0;i<n;i++){
pre[i+1]=pre[i]+arr[i].second;
}
for(int i=0;i<=n;i++){
//cout<<pre[i+1]<<" ";
}
int cevap=-1e17;
int ma=-1e17;
for(int i=0;i<n;i++){
cevap=max(cevap,pre[i+1]-arr[i].first+ma);
ma=max(ma,arr[i].first-pre[i]);
}
cout<<cevap;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
//cin>>t;
while(t--){
solve();
}
}
| # | 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... |