Interesting Sequence two points ???

Source: Internet
Author: User

Algorithm:

At a glance, this question is like a binary question. In fact, it does not satisfy the binary nature.

If S is 29 and the enumeration length starts from 1 is 2, it is not satisfied, but the maximum length is 3 .. 1 2 20 10 10 3

The correct algorithm is to use L [I] to record the maximum I expansion length to left, and R [I] to record the maximum I expansion length to right ..

/** Honi, zadatak dvoniz * Autor: Goran zuzic ** sluzbeno rjesenje, trebalo Bi dobiti SVE bodove. ukupna slozenost O (n lg n ). **/# include <algorithm> # include <functional> # include <ctime> # include <cmath> # include <cstdio> # include <cstdlib> # include <cstring> # include <set> # include <vector> # include <string> using namespace STD; const int maxn = 100100; int N, S; int A [maxn]; int L [maxn], R [maxn]; vector <in T> ubaci [maxn]; int main (void) {While (scanf ("% d", & N, & S )! = EOF) {for (INT I = 0; I <n; ++ I) {scanf ("% d", A + I);} int A = 0, B = 0; int Suma = 0; while (A <n) {If (B <n & Suma + A [B] <= s) {Suma + = A [B ++];} else {R [a] = B-A; Suma-= A [A ++] ;}} printf ("sum = % d \ n", Suma); a = B = n-1; while (A> = 0) {If (B> = 0 & Suma + A [B] <= s) {Suma + = A [B --];} else {L [a] = A-B; Suma-= A [A --] ;}} for (INT I = 0; I + 1 <n; ++ I) {int val = min (L [I], R [I + 1] ); Printf ("% d \ n", Val, I-Val + 1, I); ubaci [I-Val + 1]. push_back (I); // start point of expansion, to k} Multiset <int> PQ; For (INT I = 0; I <n; ++ I) {While (! PQ. empty () & * PQ. begin () <I) PQ. erase (PQ. begin (); For (vector <int>: iterator it = ubaci [I]. begin (); it! = Ubaci [I]. end (); ++ it) {PQ. insert (* It); printf ("I = % d \ n", I, * It);} ubaci [I]. clear (); If (! PQ. empty () printf ("% d max = % d \ n", (* PQ. rbegin ()-I + 1) * 2, * PQ. rbegin (); else printf ("0 \ n") ;}} return (0-0 );}

 

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.