The main topic: give the location of food, give the initial amount of money, ask the Granary where to put the most food received. It takes a |x-x ' | cost to get the grain to the granary.
Idea: See the range of L and B are surprisingly large, only from R to start. Can you get something out of every grain position?
First of all, to buy as much as possible, the purchase of food should be a continuous interval. For each grain location, the food that can be acquired from the location of the grain is monotonous. This can be determined by two points. The nearest point to reach all points within a range is the median, so you can determine O (1).
(Is this really a ioi question?)
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 100010using namespace Std;int cnt,range;long long Money;long long src[max],sum[max];inline long long Calc (int l,int r) {int Mid = (L + R) >> 1;long Long pos = Src[mid];return pos * (mid-l)-(sum[mid-1]-sum[l-1]) + sum[r]-Sum[mid ]-Pos * (R-MID);} int main () {CIN >> cnt >> range >> money;for (int i = 1; I <= cnt; ++i) {scanf ("%lld", &src[i]); sum[ I] = Sum[i-1] + src[i];} int _max = 0;for (int i = 1; I <= cnt; ++i) {int L = 1,r = cnt-i + 1,ans = 0;while (l <= r) {int mid = (L + r) >& Gt 1;if (Calc (i,i + mid-1) <= money) L = mid + 1,ans = Mid;elser = mid-1;} _max = max (_max,ans);} cout << _max << endl;return 0;}
Bzoj 2600 IOI Ricehub two minutes