이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
const int inf = 1e9 + 69;
for(int i = 0;i < n;i++) {
int res = 1, l = i - 1, r = i + 1;
long long t = 0;
while(t <= B) {
int x = inf, y = inf;
if(l >= 0)
x = a[i] - a[l];
if(r < n)
y = a[r] - a[i];
if(t + x > B)
x = inf;
if(t + y > B)
y = inf;
if(x == inf && y == inf)
break;
if(x <= y)
t += x, --l;
else
t += y, ++r;
++res;
}
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;
// }
# | 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... |