Submission #1066392

#TimeUsernameProblemLanguageResultExecution timeMemory
1066392DeathIsAweRice Hub (IOI11_ricehub)C++14
100 / 100
11 ms3684 KiB
#include "ricehub.h" #include <bits/stdc++.h> using namespace std; #define ll long long int besthub(int r, int l, int x[], long long b) { int ans = 0; int left = 0, right = 0, middle = 0; ll leftsum = 0, rightsum = 0; bool prev = true; while (right != r - 1) { if (prev) { if ((right - left + 1) % 2 == 0) { right++; middle++; leftsum += (ll)(middle - left) * (x[middle] - x[middle - 1]); rightsum -= (ll)(right - middle) * (x[middle] - x[middle - 1]); rightsum += x[right] - x[middle]; if (leftsum + rightsum > b) { prev = false; } else { prev = true; ans = max(ans, right - left + 1); } } else { right++; rightsum += x[right] - x[middle]; if (leftsum + rightsum > b) { prev = false; } else { prev = true; ans = max(ans, right - left + 1); } } } else { if ((right - left + 1) % 2 == 0) { left++; middle++; leftsum += (ll)(middle - left + 1) * (x[middle] - x[middle - 1]); rightsum -= (ll)(right - middle + 1) * (x[middle] - x[middle - 1]); leftsum -= x[middle] - x[left - 1]; if (leftsum + rightsum > b) { prev = false; } else { prev = true; ans = max(ans, right - left + 1); } } else { left++; leftsum -= x[middle] - x[left - 1]; if (leftsum + rightsum > b) { prev = false; } else { prev = true; ans = max(ans, right - left + 1); } } } //cout << left << ' ' << middle << ' ' << right << ' ' << leftsum << ' ' << rightsum << '\n'; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...