#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair
#ifndef ONLINE_JUDGE
# define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
# define LOG(x) ((void)0)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;
template<typename T> T getint() {
T val=0;
char c;
bool neg=false;
while((c=gc()) && !(c>='0' && c<='9')) {
neg|=c=='-';
}
do {
val=(val*10)+c-'0';
} while((c=gc()) && (c>='0' && c<='9'));
return val*(neg?-1:1);
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)
int n;
int L,R,K;
int a[55];
int dp_mx[51][51][2555];
int calc_mx(int i, int j, int k) {
if(i>n) return (j==0?0:-1e9);
if(dp_mx[i][j][k]!=-1) return dp_mx[i][j][k];
int ans=calc_mx(i+1,j,k);
if(k-(i-L)>=0 && j>0) ans=max(ans, calc_mx(i+1,j-1,k-(i-L))+a[i]);
return dp_mx[i][j][k]=ans;
}
int dp_mn[51][51][2555];
int calc_mn(int i, int j, int k) {
if(i==0) return (j==0?0:1e9);
if(dp_mn[i][j][k]!=-1) return dp_mn[i][j][k];
int ans=calc_mn(i-1,j,k);
if(k-(L-i)>=0 && j >0) ans=min(ans, calc_mn(i-1,j-1,k-(L-i))+a[i]);
return dp_mn[i][j][k]=ans;
}
int main() {
IO;
cin>>n>>L>>R>>K;
for(int i=1;i<=n;++i) cin>>a[i];
int szum=0;
for(int i=L;i<=R;++i) szum+=a[i];
memset(dp_mn,-1,sizeof dp_mn);
memset(dp_mx,-1,sizeof dp_mx);
int ans=1e9;
for(int i=0;i<L;++i) {
for(int j=0;j<=K;++j) {
ans=min(ans, szum-calc_mx(L,i,j)+calc_mn(L-1,i,K-j));
}
}
cout<<ans<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
52344 KB |
Output is correct |
2 |
Correct |
32 ms |
52344 KB |
Output is correct |
3 |
Correct |
33 ms |
52344 KB |
Output is correct |
4 |
Correct |
32 ms |
52344 KB |
Output is correct |
5 |
Correct |
36 ms |
52344 KB |
Output is correct |
6 |
Correct |
32 ms |
52472 KB |
Output is correct |
7 |
Incorrect |
35 ms |
52344 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
52344 KB |
Output is correct |
2 |
Correct |
32 ms |
52344 KB |
Output is correct |
3 |
Correct |
33 ms |
52344 KB |
Output is correct |
4 |
Correct |
32 ms |
52344 KB |
Output is correct |
5 |
Correct |
36 ms |
52344 KB |
Output is correct |
6 |
Correct |
32 ms |
52472 KB |
Output is correct |
7 |
Incorrect |
35 ms |
52344 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
52344 KB |
Output is correct |
2 |
Correct |
32 ms |
52344 KB |
Output is correct |
3 |
Correct |
33 ms |
52344 KB |
Output is correct |
4 |
Correct |
32 ms |
52344 KB |
Output is correct |
5 |
Correct |
36 ms |
52344 KB |
Output is correct |
6 |
Correct |
32 ms |
52472 KB |
Output is correct |
7 |
Incorrect |
35 ms |
52344 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
52344 KB |
Output is correct |
2 |
Correct |
32 ms |
52344 KB |
Output is correct |
3 |
Correct |
33 ms |
52344 KB |
Output is correct |
4 |
Correct |
32 ms |
52344 KB |
Output is correct |
5 |
Correct |
36 ms |
52344 KB |
Output is correct |
6 |
Correct |
32 ms |
52472 KB |
Output is correct |
7 |
Incorrect |
35 ms |
52344 KB |
Output isn't correct |