Table of Contents
Edit on GithubCF - Books
Author: Benjamin Qi
(Translated)
It is easiest to use the method of two pointers. The left pointer means the beginning of the segment of books to read, the right one - the end. When moving the left pointer one unit to the right, the right pointer should be repeatedly moved to the right as long as the sum of all within the segment is less than or equal to . This way, we can find for each possible left end the rightmost possible right end. The answer to the problem is the maximum length over all possible left ends.
1#include <bits/stdc++.h>2using namespace std;34using ll = long long;5using ld = long double;6using db = double;7using str = string; // yay python!89using pi = pair<int,int>;10using pl = pair<ll,ll>;
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!