#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pi;
typedef pair<ll, pair<ll, ll> > pii;
typedef vector <ll> vi;
#define forw(i,a,b) for (ll i=a;i<=(b);i++)
#define forb(i,a,b) for (ll i=a;i>=(b);i--)
#define fast {ios::sync_with_stdio(false); cin.tie(0); }
#define fi first
#define se second
#define pu push
#define puf push_front
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fr front
#define all(a) a.begin(),a.end()
const ll oo=1e18;
const ll mod=(1<<31)-1;
const int base=31;
const int tx[5]={0,-1,0,1,0};
const int ty[5]={0,0,1,0,-1};
const ll maxN=5e5+5;
const ll maxM=2e5+5;
const ll block=700;
ll n,l,r,k,dp[55][10004][55],sum,a[105],ans;
void minimize(ll &a,ll b)
{
a=min(a,b);
}
void solve()
{
cin>>n>>l>>r>>k;
forw(i,1,n)
{
cin>>a[i];
if (l<=i && i<=r)
sum+=a[i];
}
int num=r-l+1;
forw(i,0,n)
forw(cost,0,k)
forw(j,0,n)
dp[i][cost][j]=oo;
dp[0][0][0]=sum;
forw(i,0,l-2)
{
forw(cost,0,k)
{
ll res=oo;
forw(j,0,num)
{
res=min(res,dp[i][cost][j]);
minimize(dp[i+1][cost][j],res);
if (cost+ (l+j) - (i+1) <=k)
minimize(dp[i+1][cost+ (l+j) - (i+1)][j+1],res-(a[l+j]-a[i+1]));
}
}
}
ans=sum;
forw(cost,0,k)
forw(j,0,num)
minimize(ans,dp[l-1][cost][j]);
cout<<ans;
}
int main()
{
fast;
//freopen("test.inp","r",stdin);
//freopen("test.out","w",stdout);
solve();
return 0;
}
Compilation message
holding.cpp:21:21: warning: integer overflow in expression of type 'int' results in '2147483647' [-Woverflow]
21 | const ll mod=(1<<31)-1;
| ~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
24 ms |
56236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
24 ms |
56236 KB |
Output is correct |
8 |
Correct |
1 ms |
1740 KB |
Output is correct |
9 |
Correct |
2 ms |
2380 KB |
Output is correct |
10 |
Correct |
1 ms |
2508 KB |
Output is correct |
11 |
Correct |
2 ms |
4812 KB |
Output is correct |
12 |
Correct |
2 ms |
2764 KB |
Output is correct |
13 |
Correct |
119 ms |
219964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
24 ms |
56236 KB |
Output is correct |
8 |
Correct |
1 ms |
1740 KB |
Output is correct |
9 |
Correct |
2 ms |
2380 KB |
Output is correct |
10 |
Correct |
1 ms |
2508 KB |
Output is correct |
11 |
Correct |
2 ms |
4812 KB |
Output is correct |
12 |
Correct |
2 ms |
2764 KB |
Output is correct |
13 |
Correct |
119 ms |
219964 KB |
Output is correct |
14 |
Correct |
1 ms |
708 KB |
Output is correct |
15 |
Correct |
1 ms |
2372 KB |
Output is correct |
16 |
Incorrect |
1 ms |
1616 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
24 ms |
56236 KB |
Output is correct |
8 |
Correct |
1 ms |
1740 KB |
Output is correct |
9 |
Correct |
2 ms |
2380 KB |
Output is correct |
10 |
Correct |
1 ms |
2508 KB |
Output is correct |
11 |
Correct |
2 ms |
4812 KB |
Output is correct |
12 |
Correct |
2 ms |
2764 KB |
Output is correct |
13 |
Correct |
119 ms |
219964 KB |
Output is correct |
14 |
Correct |
1 ms |
708 KB |
Output is correct |
15 |
Correct |
1 ms |
2372 KB |
Output is correct |
16 |
Incorrect |
1 ms |
1616 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |