sicily 2013
2011-01-31 23:38
260 查看
贪心,当钱足够付清前面所有的帐时才还债。
#include <iostream> using namespace std; int cost[100010]; int main() { //freopen("1.txt", "r", stdin); int n; cin >> n; int last = -1; int cur = 0; int ans = 0; int curCost = 0; int _curCost = 0; int i = 1; for(; i <= n; i++) { cin >> cost[i]; ans += i - cur; cur = i; if(cost[i] >= 0) curCost += cost[i]; else { _curCost += cost[i]; if(last == -1) last = i; } if(last != -1 && curCost + _curCost >= 0) { if(last >= cur) ans += last - cur; else ans += cur - last; cur = last; curCost += _curCost; _curCost = 0; last = -1; } } cout << ans + n - cur << endl; return 0; }
相关文章推荐
- Sicily 2013. Pay Back
- Sicily 2013 Pay Back
- sicily 2013. Pay Back
- Sicily 2013. Pay Back
- Sicily 2013. Pay Back
- USACO 2013 March contest Bronze level 总结
- 【2013Esri中国用户大会】桌面中三大全新武器
- 【VS】VS2013常用快捷键
- Exchange2013 -1- 部署前提、版本共存、硬件需求
- vs2013 + qt5.3.2 + qwt6.1.1
- 3476. 【NOIP2013初赛】整除
- 2013腾讯编程马拉松初赛第5场(3月25)(HDU 4525 HDU4526 HDU4527 HDU4528 HDU4529)
- sicily 1752.选择
- Visual Studio 2013开发 mini-filter driver step by step (3) - 查看运行结果
- A Step-by-Step Guide to Using iAd Workbench to Promote Your iOS Apps June 11, 2013, Raymond in Badmi
- Visual Studio 2013中用VSIX创建项目模版
- WPS表格2013借助随机函数randbetween做一个彩票模拟系统
- 2013 浦东新区招生办公室的入学须知
- CDC 2013 北京站手记
- InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)