이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
int n;
vector<pii> a;
vector<int> val;
int get(int x,int y){
return val[y+1]-val[x];
}
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int rd()
{
int s=0;
char ch=getchar(),last;
while(ch<'0'||ch>'9') last=ch,ch=getchar();
while(ch>='0'&&ch<='9') s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
return last=='-'?-s:s;
}
int num[100];
inline void rt(int x)
{
if(x<0) putchar('-'),x=-x;;
int len=0;
do num[len++]=x%10;while(x/=10);
while(len--) putchar(num[len]+'0');
}
void solve(){
n=rd();
a.resize(n);val.resize(n+2);
for(auto&x:a) x.first=rd(),x.second=rd();
sort(a.begin(),a.end());
for(int i=1;i<=n;i++) val[i]=val[i-1]+a[i-1].second;
int mx=0,ans=0;
for(int i=0;i<n;i++){
mx=max(mx,a[i].first-get(0,i-1));
ans=max(ans,get(0,i)-a[i].first+mx);
}
rt(ans);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'long long int rd()':
art.cpp:23:18: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
23 | return last=='-'?-s:s;
| ~~~~~~~~~^~~~~
# | 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... |