Submission #335943

#TimeUsernameProblemLanguageResultExecution timeMemory
335943aryan12Rice Hub (IOI11_ricehub)C++17
68 / 100
1065 ms1516 KiB
#include <bits/stdc++.h> #include "ricehub.h" using namespace std; int besthub(int r, int l, int x[], long long b) { long long ans = 1; for(long long i = 2; i <= r; i++) { long long left = 1, right = i, best = r; long long mid; while(left <= right) { mid = (left + right) / 2; long long FieldSituated = (mid + i) / 2, cost = 0; //cout << "left = " << left << ", right = " << right << ", mid = " << mid << ", FieldSituated = " << FieldSituated << ", cost = "; for(long long j = mid; j <= i; j++) { cost += (abs(x[j] - x[FieldSituated])); } //cout << cost << endl; if(cost <= b) { right = mid - 1; best = mid; } else { left = mid + 1; } } ans = max(ans, i - best + 1); } int lol = ans; return lol; } /*int main() { cout << "Input the number of rice fields" << endl; int r; cin >> r; cout << "Input the maximum coordinate" << endl; int l; cin >> l; cout << "Input r numbers, denoting the rice fields" << endl; int x[r + 1]; for(int i = 1; i <= r; i++) { cin >> x[i]; } cout << "Input the budget" << endl; int b; cin >> b; cout << besthub(r, l, x, b) << endl; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...