# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41097 | IvanC | Art Exhibition (JOI18_art) | C++14 | 290 ms | 12508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const int MAXN = 5*1e5 + 10;
ii vetor[MAXN];
ll soma[MAXN],maximo,N,ans;
int main(){
scanf("%lld",&N);
for(ll i = 1;i<=N;i++){
scanf("%lld %lld",&vetor[i].first,&vetor[i].second);
}
sort(vetor+1,vetor+N+1);
for(ll i = 1;i<=N;i++){
soma[i] = soma[i-1] + vetor[i].second;
}
maximo = soma[N] - vetor[N].first;
for(ll i = N;i>=1;i--){
maximo = max(maximo, soma[i] - vetor[i].first );
ans = max(ans, maximo + vetor[i].first - soma[i-1] );
}
printf("%lld\n",ans);
return 0;
}
Compilation message (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... |