이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long
int besthub(int R, int L, int X[], long long B) {
int ans=1;
ll cost=0;
int l=0,r=0;
for (int i=1; i<R; i++){
if (cost + (X[i] - X[0]) <= B){
ans++;
cost += X[i] - X[0];
r++;
}else break;
}
for (int i=1; i<R; i++){
ll dist=X[i] - X[i-1];
if (r<i){
r=i;
}else{
cost -= dist * (r-(i-1));
}
cost += dist * (i-l);
if (cost == B) {}
else if (cost < B){
while(1){
if (r+1 < R && cost + (X[r+1] - X[i]) <= B){
cost += X[r+1] - X[i];
r++;
}else break;
}
}else{ // cost > B
while(1){
if (cost <= B) break;
cost -= X[i] - X[l];
l++;
}
//try to expand
while(1){
if (r+1 < R && cost + (X[r+1] - X[i]) <= B){
cost += X[r+1] - X[i];
r++;
}else break;
}
}
ans=max(ans, r-l+1);
}
return ans;
}
# | 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... |