# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
853034 | onepunchac168 | Holiday (IOI14_holiday) | C++14 | 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 fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair <ll,ll> ii;
const char nl='\n';
void onepunchac168();
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
onepunchac168();
}
ll n,s,d;
const int N=1e5+5;
ll a[N];
void sub1()
{
priority_queue<ll,vector <ll> ,greater <ll> > qu;
ll res=0;
ll sum=0;
for (int i=1;i<=n;i++)
{
qu.push(a[i]);
sum+=a[i];
while (qu.size()>d-i+1)
{
sum-=qu.top();
qu.pop();
}
res=max(res,sum);
}
cout<<res;
}
const int M=3e3+5;
void sub2()
{
ll res=0;
for (int i=1;i<=s;i++)
{
priority_queue<ll,vector <ll> ,greater <ll> > qu;
ll sum=0;
for (int j=i;j<=n;j++)
{
qu.push(a[j]);
sum+=a[j];
if (j>=s)
{
ll pp=(s-i)+(j-s)+min(s-i,j-s);
while (qu.size()>d-pp)
{
sum-=qu.top();
qu.pop();
}
res=max(res,sum);
}
}
}
cout<<res;
}
void onepunchac168()
{
cin>>n>>s>>d;
s++;
for (int i=1;i<=n;i++)
{
cin>>a[i];
}
if (s==1)
{
sub1();
}
else sub2();
}