Ural 1247. Check a Sequence

Source: Internet
Author: User

1247. Check a sequencetime limit:0.5 second
Memory limit:64 Mbthere is a sequence of integer numbersA1,A2,...,AS, and a positive integerN. It ' s known that all elements of the sequence {AI} satisfy the restriction 0≤Ai≤100. Moreover, it's known the sum of all elements of the sequence are equal toS+N. You is to write a program that given a sequence {AI} and a numberNWould answer the Question:is it true that for all 1≤I≤J≤SThe following inequality holds:AI+AI+1 + ... +AJ≤J–I+ 1) +N? Inputthe first input line contains, separated with a space positive numbersSandNThat does not exceed 30000. Then followSLines with one number in a line that is elements of the sequence {AI}. Outputoutput "YES", if the mentioned above inequality holds for all the values of the parametersIandJ, and "NO" otherwise. Samples
input Output
4 32302
YES
4 510 53
NO
problem Author:Alexander Mironenko
problem Source:Ural State University Personal Programming Contest, March 1, 2003Tags:None()difficulty:245 Test Instructions: Ask if a sequence is satisfied for any i,j, there are Sigma (A[k]) <= (j-i+1) +m, I<=k<=j, where M is given, 1<=n<= 30000 Analysis: In fact, I was the idiot at first thought it was a slope dp. Later found that the formula is not Sigma (a[k]-1) <= m ... is not to the series minus one, and then do a maximum sub-section and compared to M ...
1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <cmath>5#include <deque>6#include <vector>7#include <queue>8#include <iostream>9#include <algorithm>Ten#include <map> One#include <Set> A#include <ctime> -#include <iomanip> - using namespacestd; thetypedefLong LongLL; -typedefDoubleDB; - #defineFor (I, S, T) for (int i = (s); I <= (t); i++) - #defineFord (I, S, T) for (int i = (s); I >= (t); i--) + #defineRep (i, T) for (int i = (0); i < (t); i++) - #defineREPN (i, T) for (int i = (t)-1); I >= (0); i--) + #defineRep (i, X, T) for (int i = (x); i < (t); i++) A #defineMIT (2147483647) at #defineINF (1000000001) - #defineMLL (1000000000000000001LL) - #defineSZ (x) ((int) (x). Size ()) - #defineCLR (x, y) memset (x, y, sizeof (x)) - #definePUF Push_front - #definePub push_back in #definePOF Pop_front - #definePOB pop_back to #defineFT first + #defineSD Second - #defineMk Make_pair theInlinevoidSetio (stringName) * { $     stringInput = name+". in",Panax NotoginsengOutput = name+". out"; -Freopen (Input.c_str (),"R", stdin), theFreopen (Output.c_str (),"W", stdout); + } A  theInlineintGetint () + { -     intRet =0; $     CharCh =' '; $     BOOLFlag =0; -      while(! (Ch >='0'&& Ch <='9')) -     { the         if(Ch = ='-') Flag ^=1; -Ch =GetChar ();Wuyi     } the      while(Ch >='0'&& Ch <='9') -     { WuRET = RET *Ten+ Ch-'0'; -Ch =GetChar (); About     } $     returnFlag? -Ret:ret; - } -  - Const intN =30010; A intN, M, Arr[n], Ans; +  theInlinevoidInput () - { $scanf"%d%d", &n, &m); thefor (I,1, N) scanf ("%d", &arr[i]); the } the  theInlinevoidSolve () - { in     intCnt = arr[1] -1; theAns =Cnt; thefor (I,2, N) About     { theCNT = max (cnt + arr[i)-1, Arr[i]-1); theAns =Max (Ans, Cnt); the     } +     if(Ans <= m) puts ("YES"); -     ElsePuts"NO"); the }Bayi  the intMain () the { - #ifndef Online_judge -Setio ("F"); the     #endif  the Input (); the Solve (); the     return 0; -}
View Code

Ural 1247. Check a Sequence

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.