#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fi first
#define se second
#define space " "
#define endl "\n"
#define gcd __gcd
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define md 1000000007
#define inf 1000000000000000000
#define li 500005
#define int long long
using namespace std;
int T,Q,n,m,a[li],pre[li],mx[li];
string s,t;
vector<int> v;
pair<int,int> p[li];
int32_t main(){
scanf("%lld",&n);
for(int i=1;i<=n;i++) scanf("%lld %lld",&p[i].fi,&p[i].se);
sort(p+1,p+n+1);
for(int i=1;i<=n;i++) pre[i]=pre[i-1]+p[i].se;
//~ for(int i=1;i<=n;i++) printf("%d ",pre[i]);
//~ printf("\n");
mx[n+1]=-inf;
for(int i=n;i>=1;i--){
mx[i]=max(mx[i+1],pre[i]-p[i].fi);
}
//~ for(int i=1;i<=n;i++) printf("%d ",mx[i]);
//~ printf("\n");
int cev=0;
for(int i=1;i<=n;i++){
//~ if(mx[i]-pre[i-1]+p[i].fi==14){printf("Debuggi %d\n",i);}
cev=max(cev,mx[i]-pre[i-1]+p[i].fi);
}
printf("%lld\n",cev);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'int32_t main()':
art.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
art.cpp:26:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | for(int i=1;i<=n;i++) scanf("%lld %lld",&p[i].fi,&p[i].se);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |