Submission #485999

#TimeUsernameProblemLanguageResultExecution timeMemory
485999JomnoiRice Hub (IOI11_ricehub)C++17
0 / 100
122 ms2756 KiB
#include <bits/stdc++.h> #include <ricehub.h> #define DEBUG 0 using namespace std; int cost(int R, int X[], int pos, long long B) { vector <int> truckload; for(int i = 0; i < R; i++) { truckload.push_back(abs(X[i] - pos)); } sort(truckload.begin(), truckload.end()); long long sum = 0; for(int i = 0; i < R; i++) { if(sum + truckload[i] > B) { return i; } sum += truckload[i]; } return R; } int besthub(int R, int L, int X[], long long B) { int l = 0, r = L, ans = 0; while(l <= r) { int mid = (l + r) / 2; int cost1 = cost(R, X, mid, B); int cost2 = cost(R, X, mid + 1, B); if(cost1 > cost2) { r = mid - 1; ans = max(ans, cost1); } else { l = mid + 1; ans = max(ans, cost1); } } return ans; } // int main() { // ios_base::sync_with_stdio(0); // cin.tie(0); // int r, l, b; // cin >> r >> l >> b; // int x[l]; // for(int i = 0; i < r; i++) { // cin >> x[i]; // } // cout << besthub(r, l, x, b); // return 0; // } /* 5 20 6 1 2 10 12 14 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...