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>
#include <holiday.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
ll findMaxAttraction(int n, int start, int d, int attraction[]){
ll dp[3005][8005];
memset(dp,0,sizeof(dp));
ll rs=attraction[start];
dp[start][1]=attraction[start];
for(int i = start; i<n; ++i)
for(int j = i-start+1; j<=d; ++j){
dp[i][j]=max(dp[i][j],dp[i][j-1]);
for(int k = i-1; k>=start; --k)
dp[i][j]=max(dp[i][j],dp[k][j-i+k-1]+attraction[i]), rs=max(rs,dp[i][j]);
}
for(int i = start-1; i>=0; --i)
for(int j = start-i+1; j<=d; ++j){
dp[i][j]=dp[i][j-1];
for(int k = i+1; k<n&&j>k-i; ++k)
dp[i][j]=max(dp[i][j],dp[k][j-k+i-1]+attraction[i]), rs=max(rs,dp[i][j]);
}
return rs;
}
//int n,start,d,a[MAXN];
//int main()
//{
// tt;
// if(fopen((NAME + ".INP").c_str(), "r")) fo;
// cin >> n >> start >> d;
// for(int i = 0; i<n; ++i)
// cin >> a[i];
// cout << findMaxAttraction(n,start,d,a);
//}
//5 2 7
//10 2 20 30 1
//testing
# | 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... |