思路:

  直接二分长度不可行,因为有负数。

  考虑枚举坐便删l个数,那如果可以在短时间内求出符合条件的右边最小删的数的个数,这题便可做了。

  即:当左边删l个数时,要使sum[n]-sum[l]-fsum[n+1-x] <= s成立,求出最小的x。(sum为前缀和,fsum为后缀和)

  思考后可以发现可行的fsum[x]必然要是正数,可能的答案x必然是单调递增的(x从0开始)。

  所以维护一个大于0的递增的单调栈即可,在里面二分找答案。

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const LL mod=1e9; int n,cnt,tot,ans=K,nl,id[K];
LL s,tmp,sum[K],q[K]; void check(int x)
{
int ta=lower_bound(q,q+tot+,sum[n]-sum[x]-s)-q;
if(sum[n]-sum[x]-q[ta]<=s && x+n-id[ta]+ < ans)
ans=x+n-id[ta]+,nl=x;
}
int main(void)
{
cin>>n>>s;
id[]=n+;
for(int i=,x;i<=n;i++) scanf("%d",&x),sum[i]+=sum[i-]+x;
for(int i=n;i;i--)
{
tmp+=sum[i]-sum[i-];
if(tmp>q[tot])
q[++tot]=tmp,id[tot]=i;
}
for(int i=;i<=n;i++)
{
if(id[tot]==i) tot--;
check(i);
}
if(ans>=n)
printf("-1\n");
else
printf("%d\n%d %d\n",n-ans,nl,ans-nl);
return ;
}

Problem A. Array Factory XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016的更多相关文章

  1. 【推导】【贪心】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem H. Path or Coloring

    题意:给你一张简单无向图(但可能不连通),再给你一个K,让你求解任意一个问题:K染色或者输出一条K长路径. 直接贪心染色,对一个点染上其相邻的点的颜色集合之中,未出现过的最小的颜色. 如果染成就染成了 ...

  2. 【枚举】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem D. Cutting Potatoes

    题意:有n个土豆,每个有体积V(i),你可以将每个土豆等分为不超过K份,问你最大块和最小块比值最小为多少. 直接枚举切法,只有n*K种,然后保证其为最大块,去算其他块的切法,即让其他块切得尽可能大即可 ...

  3. 【找规律】【递归】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem F. Doubling

    题意: 给你一个n,问你R(n)对应的字符串长度最小的是啥. dp打个表出来,f(i)表示i值对应的字符串的最小长度,发现f(1)=1,f(2)=2,其他的情况下,若是偶数,则恰好在其外面加一对中括号 ...

  4. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game

    题目: Problem F. Matrix GameInput file: standard inputOutput file: standard inputTime limit: 1 secondM ...

  5. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem J. Terminal

    题目:Problem J. TerminalInput file: standard inputOutput file: standard inputTime limit: 2 secondsMemo ...

  6. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem L. Canonical duel

    题目:Problem L. Canonical duelInput file: standard inputOutput file: standard outputTime limit: 2 seco ...

  7. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative

    题目:Problem A. Arithmetic DerivativeInput file: standard inputOutput file: standard inputTime limit: ...

  8. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures

    题目:Problem D. Clones and TreasuresInput file: standard inputOutput file: standard outputTime limit: ...

  9. 【二分图】【并查集】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem L. Canonical duel

    给你一个网格(n<=2000,m<=2000),有一些炸弹,你可以选择一个空的位置,再放一个炸弹并将其引爆,一个炸弹爆炸后,其所在行和列的所有炸弹都会爆炸,连锁反应. 问你所能引爆的最多炸 ...

随机推荐

  1. 手机游戏运营主要的指标是什么? 7天活跃, 14天活跃 ARPU ?如何提升游戏 app 的虚拟道具的收入?

    数据采集越细,手段越丰富,所获得的数据也就更加详实,虽然手机游戏没有网游那么复杂,但也需要数据化运营,而且是必要的,是优化游戏收入的关键,大家最主要关心的是下面三类数据的指标 1. 用户数量首先,在移 ...

  2. 将Oracle数据库转换为SQL Server

    (转发)近期为公司的一个项目数据库进行了转换,将Oracle的Db转换为SqlServer(2000或2005均可),一开始在网上找了一些资料,发现有个工具叫SwisSql的,尝试了一下,没成功,继续 ...

  3. 简单是Jedis实例(相对连接池而言)

    在引入相关jar包后,只要new一个Jedis对象,就能做redis相关操作了.以下是一个简单的jedis实例: package com.pptv.redis; import java.util.Ar ...

  4. LAMP集群项目二 初始化系统

    1.关闭防火墙 /etc/init.d/iptables stop chkconfig iptables off 2.关闭selinux cat /etc/selinux/config #查看状态 s ...

  5. JDBC通用DAO

    dbcBaseDao接口,内容如下: package com.sun4j.core.jdbc.dao; import java.io.Serializable; import java.util.Li ...

  6. If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.

    w开启缓存,缓存视图,用于后续请求. https://www.codeigniter.com/userguide3/overview/appflow.html http://codeigniter.o ...

  7. Logstash之时区问题的建议和修改---filter---and duplicate resolution.

    2. logstash es duplicate https://logstash.jira.com/browse/LOGSTASH-1875 https://logstash.jira.com/br ...

  8. ES6中的let和const

    let和const let 用来声明变量,但是所声明的变量只在let命令所在的代码块内有效 { let a=12 alert(a)//12 } alert(a)//报错 找不到 let不像var那样会 ...

  9. 如何查看电脑最大支持多少GB内存

    第一种方法: 1.打开“开始”菜单,点击“运行”按钮,也可以直接使用[Win + R]组合快捷键打开, 在弹出来的窗口输入“CMD”,然后确定或者按下回车键 2.在命令窗口输入“wmic memphy ...

  10. MySQL exists 和 not exists 的用法

    有一个查询如下: 1 SELECT c.CustomerId, c.CompanyName   2 FROM Customers c   3 WHERE EXISTS(   4     SELECT  ...