이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair <ll,ll>
#define f first
#define s second
const int N=5e5+5;
const ll INF=1e15+5;
int n;
ll ans=0,mx=0,mn=INF,sum=0,pos,tmp;
pll p[N]; // size , value
bool ok=1;
bool cmp(pll x,pll y){
if(abs(pos-x.f)!=abs(pos-y.f)) return abs(pos-x.f)<abs(pos-y.f);
else return x.s>y.s;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i=1;i<=n;i++){
cin >> p[i].f >> p[i].s;
if(p[i].s>tmp) tmp=p[i].s,pos=p[i].f;
}
sort(p+1,p+1+n,cmp);
//for(int i=1;i<=n;i++) cout << p[i].f << " " << p[i].s << "\n";
for(int i=1;i<=n;i++){
auto [a,b]=p[i];
mx=max(mx,a);
mn=min(mn,a);
sum+=b;
ans=max(ans,sum-(mx-mn));
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'int main()':
art.cpp:32:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
32 | auto [a,b]=p[i];
| ^
# | 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... |