poj 3273 Monthly Expense
来源:互联网 发布:五子棋c语言判断胜负 编辑:程序博客网 时间:2024/05/21 06:33
H - Monthly Expense
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over the next N (1 ≤ N ≤ 100,000) days.
FJ wants to create a budget for a sequential set of exactly M (1 ≤ M ≤ N) fiscal periods called "fajomonths". Each of these fajomonths contains a set of 1 or more consecutive days. Every day is contained in exactly one fajomonth.
FJ's goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.
Input
Line 1: Two space-separated integers: N and M
Lines 2.. N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day
Output
Line 1: The smallest possible monthly limit Farmer John can afford to live with.
Sample Input
7 5
100
400
300
100
500
101
400
Sample Output
500
Hint
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over the next N (1 ≤ N ≤ 100,000) days.
FJ wants to create a budget for a sequential set of exactly M (1 ≤ M ≤ N) fiscal periods called "fajomonths". Each of these fajomonths contains a set of 1 or more consecutive days. Every day is contained in exactly one fajomonth.
FJ's goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.
Input
Line 1: Two space-separated integers: N and M
Lines 2.. N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day
Output
Line 1: The smallest possible monthly limit Farmer John can afford to live with.
Sample Input
7 5
100
400
300
100
500
101
400
Sample Output
500
Hint
If Farmer John schedules the months so that the first two days are a month, the third and fourth are a month, and the last three are their own months, he spends at most $500 in any month. Any other method of scheduling gives a larger minimum monthly limit.
二分流,,二分判断比较。。。。。
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int n,m,shu[100050];int zhao(int xx){bool fafe=true;int s=0,ge=1;for (int i=1;i<=n;i++){if (s+shu[i]>xx){ge++;s=shu[i];}elses+=shu[i];}if (ge<=m) return true;else return false;}int main(){scanf("%d%d",&n,&m);{int le=0,mid,ri=0,ans;for (int i=1;i<=n;i++){scanf("%d",&shu[i]);le=max(le,shu[i]);ri+=shu[i];}while (ri>=le){mid=(ri+le)/2;if (zhao(mid)){ans=mid;ri=mid-1;}else{le=mid+1;}}printf("%d\n",ans);}return 0;}
0 0
- poj 3273 Monthly Expense
- poj-3273 Monthly Expense
- poj 3273 Monthly Expense
- poj 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ-3273-Monthly Expense
- POJ 3273 Monthly Expense
- poj 3273 Monthly Expense
- POJ 3273 Monthly Expense
- poj 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ - 3273 Monthly Expense
- POJ-3273-Monthly Expense
- POJ 3273 Monthly Expense
- android studio 添加第三方jar
- 软件工程3
- Pinot中的Inverted Index源码分析
- 乌云章华鹏:如何构建高效的安全运维服务平台
- android toast使用总结
- poj 3273 Monthly Expense
- 后续_Learn Java for Android Development (第三版)
- bzoj 3669: [Noi2014]魔法森林
- mysql数据库设计原则
- 第一章 JAVA入门_Learn Java for Android Development(第三版)
- CodeForces 665A Buses Between Cities
- linux c++ 多线程编程
- c++作业4
- 安装ntfs-3g挂载ntfs格式硬盘=centos7自学之三