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>
#include "holiday.h"
using namespace std;
typedef long long ll;
ll start0(int n, int d, int a[])
{
ll ans = 0;
map < ll, ll > m;
for(int i = 0; i < n; i++)
{
m[a[i]]++;
ll ost = d - i;
ll sum = 0;
for(ll val = 100; val >= 1; val--)
{
if(ost == 0)
break;
ll cur = min(ost, m[val]);
sum += cur * val;
ost -= cur;
}
ans = max(ans, sum);
}
return ans;
}
ll slow(int n, int start, int d, int a[])
{
ll ans = 0;
for(int left = 0; left <= start; left++)
{
multiset < ll > s;
ll sum = 0;
for(int i = left; i < start; i++)
{
s.insert(a[i]);
sum += a[i];
}
for(int right = start; right < n; right++)
{
s.insert(a[right]);
sum += a[right];
int left_len = start - left;
int right_len = right - start;
int ost = d - (left_len + right_len + min(left_len, right_len));
if(ost <= 0)
break;
while(s.size() > ost)
{
auto it = s.begin();
sum -= *it;
s.erase(it);
}
ans = max(ans, sum);
}
}
return ans;
}
long long int findMaxAttraction(int n, int start, int d, int a[])
{
if(start == 0)
return start0(n, d, a);
else
return slow(n, start, d, a);
}
Compilation message (stderr)
holiday.cpp: In function 'll slow(int, int, int, int*)':
holiday.cpp:67:28: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
67 | while(s.size() > ost)
| ~~~~~~~~~^~~~~
# | 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... |