# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
856365 | yuricon | Holiday (IOI14_holiday) | C++17 | 0 ms | 0 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 task "STOUR"
#define ll long long
#define pb push_back
const int N = 1e5 + 6;
int n, s, d, a[N];
void sub2()
{
priority_queue <int, vector <int>, greater <int> > pq;
ll sum = 0, ans = 0;
int cnt = 0;
for(int i = s; i < n; ++i)
{
sum += a[i];
cnt++;
pq.push(a[i]);
while(!pq.empty() && cnt + s - i > d)
{
sum -= pq.top();
pq.pop();
cnt--;
}
ans = max(ans, sum);
}
sum = cnt = 0;
for(int i = s; i >= 0; --i)
{
sum += a[i];
cnt++;
pq.push(a[i]);
while(!pq.empty() && cnt + i - s > d)
{
sum -= pq.top();
pq.pop();
cnt--;
}
ans = max(ans, sum);
}
cout << ans;
}
void sub3()
{
ll ans = 0;
for(int i = 0; i < n; ++i)
{
int c = d - abs(s - i);
if(i <= s)
{
priority_queue <int, vector <int>, greater <int> > pq;
ll sum = 0;
int cnt = 0;
for(int j = i; j < n; ++j)
{
sum += a[j];
cnt++;
pq.push(a[j]);
while(!pq.empty() && cnt + j - i > c)
{
sum -= pq.top();
pq.pop();
cnt--;
}
ans = max(ans, sum);
}
}
if(i >= s)
{
priority_queue <int, vector <int>, greater <int> > pq;
ll sum = 0;
int cnt = 0;
for(int j = i; j >= 0; --j)
{
sum += a[j];
cnt++;
pq.push(a[j]);
while(!pq.empty() && cnt + (i - j) > c)
{
sum -= pq.top();
pq.pop();
cnt--;
}
ans = max(ans, sum);
}
}
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> s >> d;
for(int i = 0; i < n; ++i)
{
cin >> a[i];
}
if(n <= 3000)
{
sub3();
return 0;
}
sub2();
}