Problem A. Array Factory XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016
思路:
直接二分长度不可行,因为有负数。
考虑枚举坐便删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的更多相关文章
- 【推导】【贪心】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长路径. 直接贪心染色,对一个点染上其相邻的点的颜色集合之中,未出现过的最小的颜色. 如果染成就染成了 ...
- 【枚举】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种,然后保证其为最大块,去算其他块的切法,即让其他块切得尽可能大即可 ...
- 【找规律】【递归】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,其他的情况下,若是偶数,则恰好在其外面加一对中括号 ...
- 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 ...
- 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 ...
- 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 ...
- 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: ...
- 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: ...
- 【二分图】【并查集】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),有一些炸弹,你可以选择一个空的位置,再放一个炸弹并将其引爆,一个炸弹爆炸后,其所在行和列的所有炸弹都会爆炸,连锁反应. 问你所能引爆的最多炸 ...
随机推荐
- KVC/KVO之暴力的KVC
本章将分为三个部分: KVC是什么 KVC之Set/Get KVC键值路径之Set/Get KVC是什么 KVC,即 NSKeyValueCoding,一个非正式的 Protocol,提供一种机制来间 ...
- Ubuntu 16.04 LTS 完善解决亮度调整
环境: ubuntu16.04 lts acer aspire 4752G i5-2450M 内容来源:点击这里 ubuntu无法调整屏幕亮度,对笔记本来说很耗电,同时也很刺眼,因为它是默认以最大亮度 ...
- AngularJS------各种版本下载地址
转载: http://blog.csdn.net/Rongbo_J/article/details/51325606 下载地址: github https://github.com/angular/a ...
- Sql创建约束
add constraint pk_studentno primary key(StudentNo) //主键 add constraint fk_student_grade_gradeid fore ...
- LeetCode 笔记系列16.1 Minimum Window Substring [从O(N*M), O(NlogM)到O(N),人生就是一场不停的战斗]
题目: Given a string S and a string T, find the minimum window in S which will contain all the charact ...
- /proc/iomem和/proc/ioports对应的fops
/proc/iomem和/proc/ioports对应的fops static int __init ioresources_init(void) { struct proc_dir_entr ...
- Arcengine 二次开发得到点shapefile的坐标
做二次开发的时候,想要得到Point shapfile的坐标和相应的属性,也就是Point 的(x,y)和某个属性,在网上查了一些资料,做总结如下 首先,你要确定自己要操作的图层,一般来说,得到当前操 ...
- SNORT--install ---dependency-resolve
# ./configure 遇到ERROR: checking for pfring_open in -lpcap... no ERROR! Libpcap library/headers (lib ...
- 用Python爬虫爬取广州大学教务系统的成绩(内网访问)
用Python爬虫爬取广州大学教务系统的成绩(内网访问) 在进行爬取前,首先要了解: 1.什么是CSS选择器? 每一条css样式定义由两部分组成,形式如下: [code] 选择器{样式} [/code ...
- git学习——<四>git版本管理
一.git版本管理的优势 都说git比svn强大,强大在哪呢? 首先,从部署上说:svn.cvs都是集中式的,一台服务器上部署服务,所有客户端编写的代码都要提交到该服务器上.git是分布式的,所有人都 ...