Submission #873820

#TimeUsernameProblemLanguageResultExecution timeMemory
873820StefanL2005Rice Hub (IOI11_ricehub)C++14
0 / 100
12 ms3432 KiB
#include <bits/stdc++.h> #include "ricehub.h" using namespace std; #define ll long long int besthub(int R, int L, int V[], ll B) { vector<int> X(R); vector<int> Best(R); for (int i = 0; i < R; i++) X[i] = V[i]; int c1 = 0, c2 = 0; ll sum = 0; while (c2 < R && sum + X[c2] - X[0] <= B) { sum += X[c2] - X[0]; c2++; } c2--; Best[0] = c2 + 1; for (int i = 1; i < R; i++) { if (X[i] == X[i - 1]) { Best[i] = Best[i - 1]; if (c2 < i) c2 = i; continue; } sum += (i - c1) * (X[i] - X[i - 1]) - (c2 - (i - 1)) * (X[i] - X[i - 1]); if (c2 < i) c2 = i; while (sum > B) { if (X[i] - X[c1] >= X[c2] - X[i]) { sum -= X[i] - X[c1]; c1++; } else { sum -= X[c2] - X[i]; c2++; } } while (sum < B) { int p1 = c1 - 1, p2 = c2 + 1; int sum1, sum2; if (p1 < 0) sum1 = -1; else sum1 = sum + X[i] - X[p1]; if (p2 >= R) sum2 = -1; else sum2 = sum + X[p2] - X[i]; if (sum1 != -1 && (sum1 <= B && (sum2 == -1 || sum1 <= sum2))) { sum = sum1; c1--; continue; } if (sum2 != -1 && (sum2 <= B && (sum1 == -1 || sum2 < sum1))) { sum = sum2; c2++; continue; } break; } while (c2 + 1 < R && X[c2 + 1] - X[i] < X[i] - X[c1]) { sum += X[c2 + 1] - X[i]; c2++; if (sum > B) { sum -= X[c1] - X[i]; c1++; } } Best[i] = c2 - c1 + 1; } int Max = Best[0]; for (int i = 0; i < R; i++) Max = max(Max, Best[i]); return Max; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...