# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
299786 | NicolaAbusaad2014 | Art Exhibition (JOI18_art) | C++14 | 215 ms | 24856 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n,x,z,ans=0,a,b,mx=0;
cin>>n;
a=0;
b=n-1;
pair<long long,long long>arr[n];
for(long i=0;i<n;i++){
cin>>arr[i].first>>arr[i].second;
ans+=arr[i].second;
mx=max(mx,arr[i].second);
}
sort(arr,arr+n);
ans-=(arr[n-1].first-arr[0].first);
x=0;
z=ans;
long long add[n];
add[0]=0;
for(long i=1;i<n;i++){
x-=arr[i-1].second;
x+=arr[i].first-arr[i-1].first;
add[i]=max(add[i-1],x);
}
a=0;
x=0;
for(long i=n-2;i>=0;i--){
x-=arr[i+1].second;
x+=arr[i+1].first-arr[i].first;
a=max(a,x);
ans=max(ans,z+add[i]+a);
}
ans=max(ans,mx);
cout<<ans<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |