# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
784381 | Lyrically | Holiday (IOI14_holiday) | C++17 | 5076 ms | 6664 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 pii pair<int,int>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int read(){int x;scanf("%d",&x);return x;}
void print(int x){printf("%d\n",x);}
void file(string s)
{
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
const int mod=998244353;
long long a[100005];
long long n,s,d;
long long calc(int x)
{
multiset<int> st;
for(int i=x;i<s;i++){st.insert(a[i]);}
long long res=0;
for(int i=s;i<=n;i++)
{
int lst=i-x+min(i-s,s-x);
if(lst>d){continue;}
st.insert(a[i]);
lst=d-lst;
vector<int> v;
long long cur=0;
for(int j=1;j<=lst;j++)
{
if(st.empty()){break;}
cur+=*(--st.end());
v.pb(*(--st.end()));
st.erase(--st.end());
}
res=max(res,cur);
//cout<<i<<" "<<lst<<" "<<cur<<endl;
for(auto x:v){st.insert(x);}
//for(auto v:st){cout<<v<<" ";}
//cout<<endl;
}
return res;
}
long long findMaxAttraction(int N,int S,int D,int attr[])
{
n=N,s=S+1,d=D;
rep(i,n){a[i+1]=attr[i];}
//往左去到的最远地方
long long res=0;
for(int i=1;i<=min(s,20ll);i++)
{
long long x=calc(i);
res=max(res,x);
}
for(int i=max(s-20,1ll);i<=s;i++)
{
long long x=calc(i);
res=max(res,x);
}
reverse(a+1,a+n+1);
s=n-s+1;
if(s!=1)
{
for(int i=1;i<=min(s,20ll);i++)
{
long long x=calc(i);
res=max(res,x);
}
for(int i=max(s-20,1ll);i<=s;i++)
{
long long x=calc(i);
res=max(res,x);
}
}
return res;
}
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... |