#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N 110 * 110
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
int ans, k, a[55], sm, p, sum;
short int i, j, l, r, n, t, nt, le;
int f[N][55][55];
vector <int> v, v1;
bool cmp(int i, int j) {return a[i] > a[j];}
bool cmp1(int i, int j) {return a[i] < a[j];}
int main()
{
// srand(time(0));
ios_base::sync_with_stdio(0);
iostream::sync_with_stdio(0);
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
// in("input.txt");
// out("output.txt");
cin >> n >> l >> r >> k;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = l; i <= r; i++) sm += a[i], v.pb(i);
for (i = 1; i < l; i++) v1.pb(i);
for (i = r + 1; i <= n; i++) v1.pb(i);
sort(v.begin(), v.end(), cmp);
sort(v1.begin(), v1.end(), cmp1);
for (sum = 0; sum <= k; sum++)
for (i = 0; i <= n + 1; i++)
for (j = 0; j <= n + 1; j++) f[sum][i][j] = sm + 1;
f[0][0][0] = ans = sm;
for (sum = 0; sum <= k; sum++)
for (t = 0; t < v.size(); t++)
for (le = 0; le <= v1.size(); le++)
{
if (f[sum][le][t] == sm + 1) continue;
for (i = le + 1; i <= v1.size(); i++)
for (nt = t + 1; nt <= v.size(); nt++)
{
if (abs(v1[i - 1] - v[nt - 1]) + sum <= k)
f[sum + abs(v1[i - 1] - v[nt - 1])][i][nt] = min(f[sum + abs(v1[i - 1] - v[nt - 1])][i][nt], f[sum][le][t] + a[v1[i - 1]] - a[v[nt - 1]]);
}
}
for (sum = 0; sum <= k; sum++)
for (i = 0; i <= n + 1; i++)
for (j = 0; j <= n + 1; j++)
ans = min(ans, f[sum][i][j]);
cout << ans;
}
Compilation message
holding.cpp: In function 'int main()':
holding.cpp:60:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (t = 0; t < v.size(); t++)
~~^~~~~~~~~~
holding.cpp:61:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (le = 0; le <= v1.size(); le++)
~~~^~~~~~~~~~~~
holding.cpp:66:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = le + 1; i <= v1.size(); i++)
~~^~~~~~~~~~~~
holding.cpp:67:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (nt = t + 1; nt <= v.size(); nt++)
~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
46 ms |
68992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
46 ms |
68992 KB |
Output is correct |
8 |
Correct |
8 ms |
896 KB |
Output is correct |
9 |
Correct |
18 ms |
1280 KB |
Output is correct |
10 |
Correct |
25 ms |
1408 KB |
Output is correct |
11 |
Correct |
69 ms |
2664 KB |
Output is correct |
12 |
Correct |
12 ms |
1536 KB |
Output is correct |
13 |
Correct |
223 ms |
118776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
46 ms |
68992 KB |
Output is correct |
8 |
Correct |
8 ms |
896 KB |
Output is correct |
9 |
Correct |
18 ms |
1280 KB |
Output is correct |
10 |
Correct |
25 ms |
1408 KB |
Output is correct |
11 |
Correct |
69 ms |
2664 KB |
Output is correct |
12 |
Correct |
12 ms |
1536 KB |
Output is correct |
13 |
Correct |
223 ms |
118776 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
1280 KB |
Output is correct |
16 |
Incorrect |
7 ms |
896 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
46 ms |
68992 KB |
Output is correct |
8 |
Correct |
8 ms |
896 KB |
Output is correct |
9 |
Correct |
18 ms |
1280 KB |
Output is correct |
10 |
Correct |
25 ms |
1408 KB |
Output is correct |
11 |
Correct |
69 ms |
2664 KB |
Output is correct |
12 |
Correct |
12 ms |
1536 KB |
Output is correct |
13 |
Correct |
223 ms |
118776 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
1280 KB |
Output is correct |
16 |
Incorrect |
7 ms |
896 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |