Bzoj 2600 IOI Ricehub two minutes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.