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"holiday.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 100005;
int n;
int a[N];
long long int findMaxAttraction(int n, int start, int d, int attraction[])
{
::n = n;
for (int i = 0; i < n; ++i)
a[i] = attraction[i];
ll ans = 0;
if (start == 0)
{
multiset<int> s;
ll yans = 0;
for (int i = 0; i < n; ++i)
{
s.insert(a[i]);
yans += a[i];
while (!s.empty() && sz(s) > d - i)
{
yans -= (*s.begin());
s.erase(s.begin());
}
ans = max(ans, yans);
}
return ans;
}
for (int u = start; u < n; ++u)
{
ll yans = 0;
multiset<int> s;
for (int i = start; i <= u; ++i)
{
s.insert(a[i]);
yans += a[i];
}
while (!s.empty() && sz(s) > d - (u - start))
{
yans -= (*s.begin());
s.erase(s.begin());
}
for (int i = start; i >= 0; --i)
{
if (i < start)
{
s.insert(a[i]);
yans += a[i];
}
while (!s.empty() && sz(s) > d - (2 * min(start - i, u - start) + max(start - i, u - start)))
{
yans -= (*s.begin());
s.erase(s.begin());
}
ans = max(ans, yans);
}
}
return ans;
}
# | 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... |