2013. Pay Back
来源:互联网 发布:js判断是否为对象类型 编辑:程序博客网 时间:2024/05/01 01:53
2013. Pay Back
"Never a borrower nor a lender be." O how Bessie wishes she had taken that advice! She has borrowed from or lent money to each of N (1 ≤ N ≤ 100,000) friends, conveniently labeled 1..N.
Payback day has finally come. She knows she is owed more money than she owes to the other cows. They have all lined up in a straight line, cow i standing i meters from the barn. Bessie is going to traverse the line collecting money from those who owe her and reimbursing money to those she owes.
As she moves down the line, she can request any cow who owes her money to give her the money. When she has enough money to pay off any or all of her debts, she can pay the (recently collected) money to those she owes. Cow i owes Bessie D_i money (-1,000 ≤ D_i ≤ 1,000; D_i != 0). A negative debt means that Bessie owes money to the cow instead of vice-versa.
Bessie starts at the barn, location 0. What is the minimum distance she must travel to collect her money and pay all those she owes? She must end her travels at the end of the line.
Line 1: A single integer: N Lines 2..N+1: Line i+1 contains a single integer: D_i
Line 1: A single integer that is the total metric distance Bessie must travel in order to collect or pay each cow.
5100-200250-200200
9
◦问Bessie最少花费的时间
#include<iostream>using namespace std;int main(){ int n; cin>>n; int arr[100001]; int sum=0; int p,pace; for(int i=0;i<n;i++) { cin>>arr[i]; } for(int j=0;j<n;j++) { sum+=arr[j]; if(sum<0&&sum-arr[j]>=0)//从不欠钱到欠钱的过渡点,记录下来 { p=j; } else if(sum>=0&&sum-arr[j]<0)//从欠钱到不欠钱的过渡点,马上回去还钱 { pace+=j+j-p-p; //pace记录回头还钱走过的步数 } } pace+=n; //所走过的步数还要加上一路走来的 cout<<pace<<endl; //system("pause"); return 0;}
- Sicily 2013. Pay Back
- 2013. Pay Back
- Sicily 2013. Pay Back
- Sicily 2013. Pay Back
- Sicily 2013 Pay Back
- TOJ 3203.Pay Back
- pay
- Back...
- Back
- back
- back
- Back
- BACK
- Apple Pay
- Apple Pay
- Apple Pay
- apple Pay
- Apple pay
- Tri_integral Summer Training 7 总结
- 了解搜索引擎的抓取原理是做SEO优化的关键
- 快速幂模板
- SQLite使用小结
- 用 VNC 远程图形化登录 Linux (VNC 全屏显示)
- 2013. Pay Back
- android 广播 动态绑定与静态绑定的研究
- PHP+MYSQL分页原理
- CodeForces 1A Theatre Square
- 周日期的计算
- CSS设置 使div中的图片垂直上下居中
- codility上的问题之十 iota 2011
- openCV read write RGB value
- 笔记本蓝牙模块转USB接口方法