Submission #333635

#TimeUsernameProblemLanguageResultExecution timeMemory
333635blueRice Hub (IOI11_ricehub)C++17
49 / 100
20 ms2284 KiB
#include "ricehub.h" #include <vector> using namespace std; int besthub(int R, int L, int X[], long long B) //fields, max coordinate, i'th field, budget { int fields = R; vector<long long> F(R+2); F[0] = -(2e16 + 1); F[R+1] = (4e16 + 1); for(int i = 1; i <= R; i++) F[i] = X[i-1]; int l = 1; //leftmost field int m = 1; //hub int r = 1; //rightmost field long long c = 0; //current cost int res = 1; //running result while(1) { if(F[r+1] - F[m] + c <= B) { c += F[r+1] - F[m]; r++; } else if(F[m] - F[l] > F[r+1] - F[m]) { c -= (F[m] - F[l]); l++; } else if(m < R) {//l * * m m1 * r /*if(F[m+1] - F[m] > B) { l = m = r = m+1; c = 0; continue; }*///IMPORTANT c += (F[m+1] - F[m]) * ((m - (l - 1)) - (r - m)); m++; while(c > B) { c -= F[m] - F[l]; l++; } } else break; res = max(res, r - l + 1); } return res; }

Compilation message (stderr)

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:7:9: warning: unused variable 'fields' [-Wunused-variable]
    7 |     int fields = R;
      |         ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...