1247. Check a Sequence

Time limit: 0.5 second
Memory limit: 64 MB
There is a sequence of integer numbers A1, A2, …, AS, and a positive integer N. It's known that all elements of the sequence {Ai} satisfy the restriction 0 ≤ Ai ≤ 100. Moreover, it's known that the sum of all elements of the sequence is equal to S + N. You are to write a program that given a sequence {Ai} and a number N will answer the question: is it true that for all 1 ≤ i ≤ j ≤ S the following inequality holds:
Ai + Ai+1 + … + Aj ≤ (j – i + 1) + N ?

Input

The first input line contains two separated with a space positive numbers S and N that do not exceed 30000. Then follow S lines with one number in a line that are elements of the sequence {Ai}.

Output

Output "YES", if the mentioned above inequality holds for all the values of the parameters i and j, and "NO" otherwise.

Samples

input output
4 3
2
3
0
2
YES
4 5
1
0
5
3
NO
Problem Author: Alexander Mironenko
Problem Source: Ural State University Personal Programming Contest, March 1, 2003
Difficulty: 245
 
题意:问一个数列是否满足对于任意的i,j,都有sigma(a[k]) <= (j-i+1)+M, i<=k<=j,其中M给出,1<=n<=30000
分析:
其实我这个傻逼一开始以为是斜率dp。
后来发现,那个式子不就是
sigma(a[k]-1) <= M吗。。。
不就是对数列减一,然后做个最大子段和和M比较。。。
 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int n, m, Arr[N], Ans; inline void Input()
{
scanf("%d%d", &n, &m);
For(i, , n) scanf("%d", &Arr[i]);
} inline void Solve()
{
int Cnt = Arr[] - ;
Ans = Cnt;
For(i, , n)
{
Cnt = max(Cnt + Arr[i] - , Arr[i] - );
Ans = max(Ans, Cnt);
}
if(Ans <= m) puts("YES");
else puts("NO");
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("F");
#endif
Input();
Solve();
return ;
}

ural 1247. Check a Sequence的更多相关文章

  1. 递推DP URAL 1081 Binary Lexicographic Sequence

    题目传送门 题意:问第k个长度为n的01串是什么(不能有相邻的1) 分析:dp[i][0/1] 表示前i个,当前第i个放1或0的方案数,先预处理计算,dp[i][1]只能有dp[i-1][0]转移过来 ...

  2. URAL 1081 Binary Lexicographic Sequence

    第13个位置第5个Bit :13>num[4] =>1 第四个bit 13-num[4]=5 :5<num[3] =>0 ,3-1 第三个Bit 5>num[2](3) ...

  3. URAL DP第一发

    列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scient ...

  4. myrocks复制中断问题排查

    背景 mysql可以支持多种不同的存储引擎,innodb由于其高效的读写性能,并且支持事务特性,使得它成为mysql存储引擎的代名词,使用非常广泛.随着SSD逐渐普及,硬件存储成本越来越高,面向写优化 ...

  5. LevelDB源码剖析

    LevelDB的公共部件并不复杂,但为了更好的理解其各个核心模块的实现,此处挑几个关键的部件先行备忘. Arena(内存领地) Arena类用于内存管理,其存在的价值在于: 提高程序性能,减少Heap ...

  6. Wide character in print at a2.pl line 6.

    jrhapt01:/home/tomcat/test> cat a2.pl my $str="$ARGV[0]"; use Encode; use URI::Escape; ...

  7. encode_utf8 把字符编码成字节 decode_utf8解码UTF-8到字符

    encode_utf8 $octets = encode_utf8($string); Equivalent to "$octets = encode("utf8", $ ...

  8. [Oracle][DATAGUARD] 关于确认LOGICAL STANDBY的同期状况的方法

    Oracle的DATAGUARD环境,有PHYSICAL STANDBY和LOGICAL STANDBY两种.PHYSICAL STANDBY是传输REDO传到Standby端,然后由Standby端 ...

  9. LevelDB源码分析-MemTable

    MemTable(db/memtable.h db/memtable.cc db/skiplist.h) LevelDB中存储在内存中的那部分KV数据都存储在memtable中,而memtable中的 ...

随机推荐

  1. BNU 2418 Ultra-QuickSort (线段树求逆序对)

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=2418 解题报告:就是给你n个数,然后让你求这个数列的逆序对是多少?题目中n的范围是n & ...

  2. [Effective JavaScript 笔记]第16条:避免使用eval创建局部变量

    js中的eval函数是一个强大.灵活的工具.强大的工具容易被滥用,所以了解是值得的.(本人只用过它来处理json数据).错误使用eval函数的方式一:允许它干扰作用域.调用eval函数会将其参数作为j ...

  3. Android通过URL加载网络图片

    public static Bitmap getBitmap(String path) throws IOException { URL url = new URL(path); HttpURLCon ...

  4. javascript对象转化为基本数据类型规则

    原文:Object-to-Primitive Conversions in JavaScript 对象转化为基础数据类型,其实最终都是用调用对象自带的valueOf和toString两个方法之一并获得 ...

  5. Django 的css和js压缩插件:django_compressor

    今天尝试了django_conpressor,一个在django框架中压缩css和js的插件,灰常有用 我把它加载在我的base的HTML template中,原来未经压缩的css和js是: < ...

  6. Find Leaves of Binary Tree

    Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves ...

  7. (转)maven eclipse debug

    准备工作: a. 在pom.xml中配置jetty插件: <plugins> <plugin> <groupId>org.mortbay.jetty</gro ...

  8. 71 Query Rank Min Max Successor of BST

    [本文链接] http://www.cnblogs.com/hellogiser/p/query-min-max-successor-of-bst.html [代码]  C++ Code  12345 ...

  9. 【转】javax.net.ssl.SSLHandshakeException(Cas导入证书)

    本文转自:http://my.oschina.net/laiwanshan/blog/159057 一.报错: javax.net.ssl.SSLHandshakeException 二.原因分析:C ...

  10. Python多线程(3)——Queue模块

    Queue模块支持先进先出(FIFO)队列,支持多线程的访问,包括一个主要的类型(Queue)和两个异常类(exception classes). Python 2 中的Queue模块在Python ...