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;
const int oo = 1e9 + 7;
void opt()
{
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
}
struct Artwork
{
bool operator< (Artwork otro) const
{
return size < otro.size;
}
int size, value;
};
int main()
{
opt();
int n; cin>>n;
Artwork candidates[n];
for (int i = 0; i < n; i++)
{
cin>>candidates[i].size>>candidates[i].value;
}
sort(candidates, candidates + n);
int sumAc[n];
int aux = 0;
for (int i = 0; i < n; i++)
{
aux += candidates[i].value;
sumAc[i] = aux;
}
int maxR = -oo;
for (int i = 0; i < n - 1; i++)
{
int ini = i;
for (int j = ini + 1; j < n; j++)
{
int fin = j;
int cost;
if (i == 0)
{
cost = sumAc[j];
}else
{
cost = sumAc[j] - sumAc[ini - 1];
}
cost -= (candidates[fin].size - candidates[ini].size);
maxR = max(maxR, cost);
}
}
cout<<maxR<<"\n";
}
# | 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... |