# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968484 | tset | Art Exhibition (JOI18_art) | C++14 | 0 ms | 348 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;
#define int long long
const int INF = 1e18 +42;
signed main()
{
int N;
scanf("%lld", &N);
vector<pair<int, int>> tab;
for(int iTab = 0; iTab < N; iTab++)
{
int A, B;
scanf("%lld%lld", &A, &B);
tab.push_back({A, B});
}
sort(tab.begin(), tab.end());
vector<int> cumulS(N, 0);
cumulS[0] = tab[0].second;
for(int i= 1; i<N; i++)
{
cumulS[i] = cumulS[i-1] + tab[i].second;
}
vector<int> SMalus(N);
int valueMax = -INF;
int idxMax = -INF;
for(int i=0; i<N; i++)
{
SMalus[i] = cumulS[i] - tab[i].first;
if(SMalus[i] >= valueMax)
{
valueMax = SMalus[i];
idxMax = i;
}
}
int ans = valueMax +tab[0].first;
for(int i=1; i<= idxMax; i++)
{
ans = max(ans, valueMax - cumulS[i-1] + tab[i].first);
}
printf("%lld\n", ans);
}
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... |