Codeforces Round #207 (Div. 2) A. Group of Students
2013-10-19 14:29
447 查看
#include <iostream> #include <vector> using namespace std; int main(){ int m,sum = 0; cin >> m ; vector<int> c(m+1,0); for(int i = 1; i <= m ; ++ i) {cin >> c[i];sum+=c[i];} int x,y,firstPart = 0, secondPart = 0,firstIndex = 0, secondIndex =0; cin >> x >> y; for(firstIndex = 0,secondIndex = m+1;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<<0<<endl; else{ if(firstIndex >= secondIndex) cout<<0<<endl; else{ if(sum - firstPart - secondPart > 2*(y-x)) cout<<0<<endl; else{ while(secondPart + c[secondIndex-1]<= y && (secondIndex-1) > firstIndex){ secondIndex--; secondPart+=c[secondIndex]; } if (secondIndex-1 <= firstIndex) cout<<secondIndex<<endl; else{ if(sum - secondPart > y) cout<<0<<endl; else cout<<secondIndex<<endl; } } } } }
相关文章推荐
- epoll()学习
- myeclipse配置tomcat
- iOS 设置UILabel的背景图片
- 21句经典语录
- 如何让菜单点击后不消失
- Cocos2d-x笔记(三)Sqlite数据库封装
- C# 执行bat批处理文件的小例子
- 系统安装提示Units specified don’t exist SHSUCDX can’t install现象的解决方法介
- mysql数据库的全量备份
- 一个程序员对职业生涯的思考和总结
- 递归倒序输出链表
- struts2 框架的使用注意事项
- exchange webservice访问类(日程新增和删除)
- 设计模式——装饰器(Decorator)
- Lucene 实例 IKAnalyzer中文分词器
- Windows8的JDK环境配置
- 视频质量,分辨率以及码率之间的关系
- 视频质量,分辨率以及码率之间的关系
- 获取SQL SERVER数据库表名和列名的sql语句
- 笔记7:vb.net的异步读写数据流(使用线程、委托)