이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define EPS 1e-9
#define ll long long
const int INF=1e9,mxN=5001;
const ll LINF=1e18,MOD=1e9+7;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pb push_back
#define PRINTvec(niz) { cerr<<#niz<<"="; for(auto _i:niz) cerr<<_i<<" "; cerr<<endl; }
#define PRINTpair(x) cerr<<#x<<"={"<<x.fi<<","<<x.se<<"}"<<endl;
void Solve(){
int N; cin>>N;
vector<pll> a(N+1);
for(int i=1;i<=N;i++) cin>>a[i].fi>>a[i].se;
sort(a.begin()+1,a.end());
ll res=0;
for(int i=1;i<=N;i++){
for(int j=i;j<=N;j++){
ll mn=LINF,mx=-LINF,sum=0;
for(int k=i;k<=j;k++){
mn=min(mn,a[k].fi);
mx=max(mx,a[k].fi);
sum+=a[k].se;
}
res=max(res,sum-(mx-mn));
}
}
cout<<res<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t; t=1;
//cin>>t;
while(t--){
Solve();
}
return 0;
}
# | 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... |