# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1018042 | vivkostov | Holiday (IOI14_holiday) | C++14 | 5034 ms | 4820 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>
#define endl '\n'
#include "holiday.h"
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
struct cell
{
long long int st;
bool operator<(const cell&a)const
{
return st>a.st;
}
};
priority_queue<cell>q;
long long int n,a[300005],k,st,sum;
void fil(long long int h)
{
cell g;
for(long long int i=h;i<st;i++)
{
sum+=a[i];
g.st=a[i];
q.push(g);
}
}
void read()
{
cin>>n>>k>>st;
cell h;
for(long long int i=1;i<=n;i++)
{
cin>>a[i];
}
long long int p=k,otg=0;
for(long long int i=1;i<=st;i++)
{
for(long long int j=st;j<=n;j++)
{
p-=min(st-i,j-st);
p-=j-i;
if(p<=0)break;
if(j==st)
{
fil(i);
}
sum+=a[j];
h.st=a[j];
q.push(h);
while(p<q.size())
{
//cout<<q.top().st<<" "<<i<<" "<<j<<" "<<q.size()<<endl;
sum-=q.top().st;
q.pop();
}
p=k;
otg=max(otg,sum);
}
p=k;
sum=0;
while(!q.empty())q.pop();
}
cout<<otg<<endl;
}
long long int findMaxAttraction(int N,int start,int d,int attraction[])
{
n=N;
st=start+1;
k=d;
cell h;
for(long long int i=1;i<=n;i++)
{
a[i]=attraction[i-1];
}
long long int p=k,otg=0;
for(long long int i=1;i<=st;i++)
{
for(long long int j=st;j<=n;j++)
{
p-=min(st-i,j-st);
p-=j-i;
if(p<=0)break;
if(j==st)
{
fil(i);
}
sum+=a[j];
h.st=a[j];
q.push(h);
while(p<q.size())
{
sum-=q.top().st;
q.pop();
}
p=k;
otg=max(otg,sum);
}
sum=0;
p=k;
while(!q.empty())q.pop();
}
return otg;
}
/*int main()
{
speed();
read();
return 0;
}
*/
Compilation message (stderr)
# | 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... |