# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
329824 | TLP39 | Solar Storm (NOI20_solarstorm) | C++14 | 435 ms | 118620 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;
int main()
{
int n,s;
long long int k;
scanf("%d %d %lld",&n,&s,&k);
int d[n+1]={};
int v[n]={};
for(int i=1;i<n;i++)
{
scanf("%d",&d[i]);
}
for(int i=0;i<n;i++)
{
scanf("%d",&v[i]);
}
int ma[n]={};
int po=0,pr=0;
long long int sum=0;
while(po<n || pr<n)
{
if(po==n)
{
ma[pr]=n-1;
pr++;
}
else if(sum<=k)
{
po++;
sum+=(long long)1*d[po];
}
else
{
ma[pr]=po-1;
pr++;
sum-=(long long)1*d[pr];
}
}
int di[30]={};
int pp=0;
int temp=s;
while(temp>0)
{
di[pp]=temp;
pp++;
temp=temp/2;
}
sort(di,di+pp);
int res[pp][n];
memset(res,0,sizeof res);
for(int i=0;i<n;i++)
{
res[0][i]=ma[ma[i]];
}
for(int i=1;i<pp;i++)
{
for(int j=0;j<n;j++)
{
if(di[i]%2==0)
{
if(res[i-1][j]==n-1)
{
res[i][j]=n-1;
}
else
{
res[i][j]=res[i-1][res[i-1][j]+1];
}
}
else
{
if(res[i-1][j]==n-1)
{
res[i][j]=n-1;
}
else
{
res[i][j]=res[i-1][res[i-1][j]+1];
if(res[i][j]!=n-1)
{
res[i][j]=res[0][res[i][j]+1];
}
}
}
}
}
long long int val[n+1];
int be;
val[0]=0;
for(int i=1;i<=n;i++)
{
val[i]=val[i-1]+(long long)1*v[i-1];
}
long long int maxx=0,hol;
for(int i=0;i<n;i++)
{
hol=val[res[pp-1][i]+1]-val[i];
if(hol>maxx)
{
maxx=hol;
be=i;
}
}
printf("%d\n",s);
for(int i=0;i<s;i++)
{
printf("%d ",ma[be]+1);
be=res[0][be]+1;
if(be>=n)
{
be=n-1;
}
}
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |