제출 #737447

#제출 시각아이디문제언어결과실행 시간메모리
737447josanneo22Art Exhibition (JOI18_art)C++17
100 / 100
93 ms14892 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...