# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66829 | ege_eksi | Art Exhibition (JOI18_art) | C++14 | 2 ms | 252 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<iostream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<algorithm>
using namespace std;
bool mycomp(pair<long long int,int> x , pair<long long int,int> y)
{
if(x.first < y.first)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int n;
scanf("%d",&n);
pair<long long int,int> *a = new pair<long long int,int>[n];
for(int i = 0 ; i < n ; i++)
{
scanf("%lli %d" , &a[i].first , &a[i].second);
}
sort(a , a+n , mycomp);
pair<long long int , long int> *d = new pair<long long int , long int>[n];
int cnt = 0;
d[0] = a[0];
for(int i = 1 ; i < n ; i++)
{
if(d[cnt].first != a[i].first)
{
cnt++;
d[cnt] = a[i];
}
else
{
d[cnt].second += a[i].second;
}
}
long long int *prefix = new long long int[cnt];
prefix[0] = d[0].second;
for(int i = 1 ; i <= cnt ; i++)
{
prefix[i] = prefix[i-1] + d[i].second;
}
long long int ans = INT_MIN;
for(int i = 0 ; i <= cnt ; i++)
{
for(int j = i+1 ; j <= cnt ; j++)
{
long long int value;
if(i == 0)
{
value = prefix[j];
}
else
{
value = prefix[j] - prefix[i-1];
}
ans = max(ans , value - (d[j].first - d[i].first));
}
}
printf("%d",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... |