Codeforces Round #207 (Div. 2) A. Group of Students
#include <iostream>
#include <vector> using namespace std; int main(){
int m,sum = ;
cin >> m ;
vector<int> c(m+,);
for(int i = ; i <= m ; ++ i) {cin >> c[i];sum+=c[i];}
int x,y,firstPart = , secondPart = ,firstIndex = , secondIndex =;
cin >> x >> y;
for(firstIndex = ,secondIndex = m+;firstIndex < secondIndex;){
if (firstPart < x) firstPart+=c[++firstIndex];
if (secondPart < x) secondPart += c[--secondIndex];
if( firstPart >= x && secondPart >= x ) break;
}
if(firstPart > y || secondPart > y) cout<<<<endl;
else{
if(firstIndex >= secondIndex) cout<<<<endl;
else{
if(sum - firstPart - secondPart > *(y-x)) cout<<<<endl;
else{
while(secondPart + c[secondIndex-]<= y && (secondIndex-) > firstIndex){
secondIndex--;
secondPart+=c[secondIndex];
}
if (secondIndex- <= firstIndex) cout<<secondIndex<<endl;
else{
if(sum - secondPart > y) cout<<<<endl;
else cout<<secondIndex<<endl;
}
}
}
}
}
Codeforces Round #207 (Div. 2) A. Group of Students的更多相关文章
- Codeforces Round #207 (Div. 2)A B C E 水 思路 set 恶心分类
A. Group of Students time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)
题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...
- Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)
脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...
- Codeforces Round #207 (Div. 1)B(数学)
数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include< ...
- Codeforces Round #207 (Div. 2)C
读错题意了..线段树延迟标记 白刷这么多线段树 #include <iostream> #include<cstdio> #include<cstring> #in ...
- Codeforces Round #207 (Div. 2)
A:超级大水题: 代码: #include<cstdio> #define maxn 105 using namespace std; int n,a[maxn],x,y,ans; int ...
- Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)
题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...
- Codeforces Round #207 (Div. 1) D - Bags and Coins 构造 + bitset优化dp + 分段查找优化空间
D - Bags and Coins 思路:我们可以这样构造,最大的那个肯定是作为以一个树根,所以我们只要找到一个序列a1 + a2 + a3 .... + ak 并且ak为 所有点中最大的那个,那么 ...
- Codeforces Round #207 (Div. 1) B (gcd的巧妙运用)
比赛的时候不知道怎么写... 太弱了. 看了别人的代码,觉得这个是个经典的知识点吧. gcd的巧妙运用 自己想的时候苦苦思考怎么用dp求解. 无奈字符串太长而想不出好的算法. 其实在把a和b字符串都分 ...
随机推荐
- twisted udp编程
概述 Unlike TCP, UDP has no notion of connections. A UDP socket can receive datagrams from any server ...
- 15.含有指针成员的类的拷贝[ClassCopyConstructorWithPointerMember]
[题目] 下面是一个数组类的声明与实现.请分析这个类有什么问题,并针对存在的问题提出几种解决方案. C++ Code 123456789101112131415161718192021222324 ...
- 利用VMware虚拟机(Android-x86 2.2)和eclipse,调试安卓代码
下载 android-x86-2.2-generic.iso (这里包含eth0) http://www.android-x86.org/download XP32位 只能使用 VMware Wor ...
- linux常见问题集锦
本文转自 http://bbs.chinaunix.net/thread-3668921-1-1.html,在此感谢作者分享 一.填空题: 1. 在Linux系统中,以 文件 方式访问设备 . 2. ...
- ListView配合CheckBox出现position位置错误的解决
最近做checkBox和ListView配合使用,想把position的位置传入到 checkBox的onCheckedChanged,于是我就在getView的时候, 把position通过chec ...
- CSS3 background-size 属性值:cover
当设置值为cover,可以呈现出图片铺满浏览器内容的视觉效果 实例 规定背景图像的尺寸: div { background:url(img_flwr.gif); background-size:80p ...
- [原]网站跨站点脚本,Sql注入等攻击的处理
从360安全论坛里找到的一段代码,经过整理封装,直接在站点Global.asax文件或写一个HttpModule来拦截恶意请求即可: http://bbs.webscan.360.cn/forum.p ...
- hdu 5115 区间dp ***
题意:有n只狼,每只狼有两种属性,一种攻击力一种附加值,我们没杀一只狼,那么我们受到的伤害值为这只狼的攻击值与它旁边的两只狼的附加值的和,求把所有狼都杀光受到的最小的伤害值. 枚举中间k作为最后杀死的 ...
- (六)WebRTC手记之WebRtcVideoEngine2模块
转自:http://www.cnblogs.com/fangkm/p/4401143.html 终于讲到视频数据的编码发送模块了,不容易.总体来说也看了不少时间WebRTC的源码了,最大的感触就是各个 ...
- etc/profile和/etc/environment的比较
转自:http://andy136566.iteye.com/blog/1025338 先将export LANG=zh_CN加入/etc/profile ,退出系统重新登录,登录提示显示英文.将/e ...