이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Balgabaev Mansur
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define pb push_back
#define int long long
using namespace std;
const int N=1e5+7;
const int MOD=1e9+7;
const int INF=1e18;
int binpow (int a, int n) {
if (n == 0)
return 1;
if (n % 2 == 1)
return binpow (a, n-1) * a;
else {
int b = binpow (a, n/2);
return b * b;
}
}
pair<int,int>p[N];
pair<int,int>p1[N];
int pref[N];
void solve(){
int n;
cin >> n;
int ans=0;
for(int i = 1 ; i <= n ; i++){
cin >> p[i].first >> p[i].second;
}
sort(p+1,p+1+n);
pref[0]=0;
for(int i = 1 ; i <= n ; i++){
pref[i]=pref[i-1]+p[i].second;
}
for(int i = 1 ; i <= n ; i++){
for(int j = i ; j <= n ; j++){
int mx=p[j].first;
int mn=p[i].first;
int sm=pref[j]-pref[i-1];
ans=max(ans,(sm-(mx-mn)));
}
}
cout << ans;
}
signed main() {
// freopen("closing.in", "r", stdin);
// freopen("closing.out", "w", stdout);
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int test = 1,cntx=1;
//cin >> test;
while (test--) {
//cout << "Case " << cntx << ':' << '\n';
solve();
cntx++;
}
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... |