#include <bits/stdc++.h>
#include "ricehub.h"
#define f first
#define s second
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int n = R;
int a[n];
for(int i = 0;i < n;i++)
a[i] = X[i];
int ans = 0;
for(int i = 0;i < n;i++) {
multiset<int> st;
for(int j = i;j >= 0;j--) {
if(a[i] - a[j] > B)
break;
st.insert(abs(a[j] - a[i]));
}
for(int j = i + 1;j < n;j++) {
if(a[j] - a[i] > B)
break;
st.insert(abs(a[j] - a[i]));
}
int res = 0;
long long t = 0;
for(auto x : st) {
if(t + x <= B) {
t += x;
++res;
}
else
break;
}
ans = max(ans, res);
}
return ans;
// set<int> levo, desno;
// long long t = 0;
// desno.insert(0);
// for(int i = 1;i < n;i++) {
// if(t + a[i] - a[0] <= B) {
// desno.insert(i);
// t += a[i] - a[0];
// ++ans;
// }
// }
// for(int i = 1;i < n;i++) {
// t -= ((int)desno.size() - 1) * (a[i] - a[i - 1]);
// t += ((int)levo.size() + 1) * (a[i] - a[i - 1]);
// if(desno.size() > 0)
// desno.erase(desno.begin());
// desno.insert(i);
// levo.insert(i - 1);
// while(levo.size() > 0 && t > B) {
// int x = *levo.begin();
// t -= (a[i] - a[x]);
// levo.erase(levo.begin());
// }
// int j = *--desno.end() + 1;
// while(j < n) {
// if(t + a[j] - a[i] <= B) {
// t += a[j] - a[i];
// desno.insert(j++);
// }
// else
// break;
// }
// while(j < n && levo.size() > 0) {
// int x = *levo.begin();
// if(t - (a[i] - a[x]) + a[j] - a[i] <= B) {
// t = t - (a[i] - a[x]) + a[j] - a[i];
// levo.erase(levo.begin());
// desno.insert(a[j++]);
// }
// else
// break;
// }
// ans = max(ans, (int)levo.size() + (int)desno.size());
// }
// return ans;
}
// signed main()
// {
// ios_base::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
// int tt = 1;
// //cin >> tt;
// while(tt--) {
// int n, k;
// long long x;
// cin >> n >> k >> x;
// int a[n];
// for(int i = 0;i < n;i++)
// cin >> a[i];
// cout << besthub(n, k, a, x);
// }
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
308 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
13 ms |
212 KB |
Output is correct |
22 |
Correct |
13 ms |
212 KB |
Output is correct |
23 |
Correct |
14 ms |
336 KB |
Output is correct |
24 |
Correct |
14 ms |
212 KB |
Output is correct |
25 |
Correct |
14 ms |
212 KB |
Output is correct |
26 |
Correct |
17 ms |
212 KB |
Output is correct |
27 |
Correct |
15 ms |
328 KB |
Output is correct |
28 |
Correct |
13 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
44 ms |
352 KB |
Output is correct |
4 |
Correct |
45 ms |
340 KB |
Output is correct |
5 |
Correct |
5 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
60 ms |
344 KB |
Output is correct |
8 |
Correct |
59 ms |
340 KB |
Output is correct |
9 |
Correct |
13 ms |
328 KB |
Output is correct |
10 |
Correct |
13 ms |
212 KB |
Output is correct |
11 |
Correct |
35 ms |
340 KB |
Output is correct |
12 |
Correct |
34 ms |
340 KB |
Output is correct |
13 |
Correct |
68 ms |
344 KB |
Output is correct |
14 |
Correct |
72 ms |
340 KB |
Output is correct |
15 |
Correct |
16 ms |
212 KB |
Output is correct |
16 |
Correct |
14 ms |
212 KB |
Output is correct |
17 |
Correct |
40 ms |
340 KB |
Output is correct |
18 |
Correct |
39 ms |
340 KB |
Output is correct |
19 |
Correct |
67 ms |
340 KB |
Output is correct |
20 |
Correct |
66 ms |
340 KB |
Output is correct |
21 |
Execution timed out |
1085 ms |
468 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1073 ms |
660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |