# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1050179 | vjudge1 | Art Exhibition (JOI18_art) | C++17 | 0 ms | 344 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
int n;
cin>>n;
vector<pair<ll,ll>> v;
ll s=0;
for(int i=0; i<n; i++) {
ll t1,t2;
cin>>t1>>t2;
s+=t2;
v.push_back({t1,0-t2});
}
sort(v.begin(),v.end());
for(int i=0; i<v.size(); i++)
v[i].second=0-v[i].second;
ll mn=0,mx=n-1,fmn=0,fmx=n-1;
s-=v[mx].first-v[mn].first;
ll s2=s;
while(fmn<mx) {
//cout<<"currently "<<mn<<' '<<mx<<' '<<s<<'\n';
ll tans=s;
for(int j=mn; j<=fmn; j++) {
//cout<<tans<<"+=("<<v[j+1].first<<"-"<<v[j].first<<")-"<<v[j].second<<"=";
tans+=(v[j+1].first-v[j].first)-v[j].second;
//cout<<tans<<'\n';
}
if(tans>s) {
mn=fmn+1;
s=tans;
//cout<<"\n\n";
}
//else cout<<"but it didn't matter\n\n";
fmn++;
}
while(mn<fmx) {
//cout<<"currently "<<mn<<' '<<mx<<' '<<s<<'\n';
ll tans=s;
for(int j=mx; j>=fmx; j--) {
//cout<<tans<<"+=("<<v[j].first<<"-"<<v[j-1].first<<")-"<<v[j].second<<"=";
tans+=(v[j].first-v[j-1].first)-v[j].second;
//cout<<tans<<'\n';
}
if(tans>s) {
mx=fmx-1;
s=tans;
//cout<<"\n\n";
}
//else cout<<"but it didn't matter\n\n";
fmx--;
}
mn=0;
mx=n-1;
fmn=0;
fmx=n-1;
while(mn<fmx) {
//cout<<"currently "<<mn<<' '<<mx<<' '<<s2<<'\n';
ll tans=s2;
for(int j=mx; j>=fmx; j--) {
//cout<<tans<<"+=("<<v[j].first<<"-"<<v[j-1].first<<")-"<<v[j].second<<"=";
tans+=(v[j].first-v[j-1].first)-v[j].second;
//cout<<tans<<'\n';
}
if(tans>s2) {
mx=fmx-1;
s2=tans;
//cout<<"\n\n";
}
//else cout<<"but it didn't matter\n\n";
fmx--;
}
while(fmn<mx) {
//cout<<"currently "<<mn<<' '<<mx<<' '<<s2<<'\n';
ll tans=s2;
for(int j=mn; j<=fmn; j++) {
//cout<<tans<<"+=("<<v[j+1].first<<"-"<<v[j].first<<")-"<<v[j].second<<"=";
tans+=(v[j+1].first-v[j].first)-v[j].second;
//cout<<tans<<'\n';
}
if(tans>s2) {
mn=fmn+1;
s2=tans;
//cout<<"\n\n";
}
//else cout<<"but it didn't matter\n\n";
fmn++;
}
cout<<max(s,s2);
}
컴파일 시 표준 에러 (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... |