思路:

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

  考虑枚举坐便删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. 基于JEECG的代码模板自动生成

    1.基于JEECG3.5.2,提供多种数据源的代码生成,目前支持Oracle良好: 2.可动态配置数据源: 可动态配置模板集合,基于freemarker的模板文件: 可选择需要生成的数据表: 可导入一 ...

  2. jboss6.4 域模式自动部署

    1.通过jenkins传递部署包到服务器,调用自动部署shell完成jboss6.4的域模式部署: 2.自动部署shell如下: 完成部署包重命名(从jenkins过来的包可能没有改名:). 调用jb ...

  3. 编程之美 set 16 拈游戏分析(1)

    题目 N 个石头排成一行, 每块石头有固定的位置和编号, 两个玩家依次取石头, 每个玩家可以取其中的任一块石头, 或者相邻的两个石头. 石头在游戏过程中不能移位, 最后将剩下的石头依次取光的玩家获胜 ...

  4. tinker

    Ios前一段时间因为热更新被强制下架也算是最大闻了,但Android没关系,继续玩 首先tinker比Andfix好多了,版本现在都到1.7.11了,Andfix不支持yunos, 现在项目中没有用到 ...

  5. Oracle索引相关

    oracle的索引分为5种:唯一索引,组合索引,反向键索引,位图索引,基于函数的索引. 创建索引的标准语法: CREATE INDEX 索引名 ON 表名 (列名) TABLESPACE 表空间名; ...

  6. linux安装yaf(ubuntu教程)

    $PHP_BIN/phpize 这个是什么 其实这个是一个扩展 apt-get install php5-dev 这样电脑会帮你自己配置了,很简单的下面我们就下载扩展包了http://pecl.php ...

  7. LeetCode-Add and Search Word

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  8. PHP使用 DOMDocument创建和解析xml文件

    <!-- DOMDocument生成XML文件 --><?php//声明一个DOMDocument对象$_doc=new DOMDocument('1.0', 'utf-8'); / ...

  9. Oracle Schema Objects——Tables——TableStorage

    Oracle Schema Objects Table Storage Oracle数据库如何保存表数据? Oracle Database uses a data segment in a table ...

  10. java 常用资源

    java高手真经:http://pan.baidu.com/share/link?uk=2100475681&shareid=2381645927#path=%252F%255Bwww.jav ...