Monthly Expense【二分】

B - Monthly Expense

?POJ - 3273?

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.

AC代碼

?

#include <cstdio>
#include <iostream>
using namespace std;
int N,M;
const int inf=10000000;
int money[105000];
bool judge(int mid)
{int sum=0,num=0;for(int i=0;i<N;i++){if(sum+money[i]>mid){sum=money[i];num++;continue;}sum+=money[i];}return num<M;
}
int main()
{while(cin>>N>>M){int max1=0;for(int i=0;i<N;i++){cin>>money[i];if(money[i]>max1)max1=money[i];}int left=max1,right=inf;int mid=0;for(int i=0;i<100;i++){mid=(right+left)/2;if(judge(mid))right=mid;elseleft=mid;}cout<<right<<endl;}return 0;
}

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/536430.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/536430.shtml
英文地址,請注明出處:http://en.pswp.cn/news/536430.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

關于HTTP協議,一篇就夠了

原文地址&#xff1a;https://www.cnblogs.com/ranyonsue/p/5984001.html HTTP簡介 HTTP協議是Hyper Text Transfer Protocol&#xff08;超文本傳輸協議&#xff09;的縮寫,是用于從萬維網&#xff08;WWW:World Wide Web &#xff09;服務器傳輸超文本到本地瀏覽器的傳送協議…

Oracle關聯查詢-數據類型不一致問題 ORA-01722: 無效數字

一、存在表A和表B&#xff0c;都包含字段user_no&#xff0c;但數據類型不一致&#xff0c;如下&#xff1a; create table A ( user_id varchar2(20), user_no number(12,0), xxx ); create table B ( user_name varchar2(60), user_no varchar2(20), xxx ); 二、現有某項業務…

1096: 字符逆序

1096: 字符逆序 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 2017 Solved: 1059 [Submit][Status][Web Board] Description 將一個字符串str的內容顛倒過來&#xff0c;并輸出。str的長度不超過100個字符。 Input 輸入包括一行。 第一行輸入的字符串。 Output 輸出…

Ajax_Apache訪問資源文件的權限配置、資源存放路徑配置、配置虛擬主機、動態網站靜態網站區別...

1、配置資源的訪問權限 修改配置文件&#xff1a;httpd.conf 文件 改完之后要重啟 2、切換資源默認存放目錄www 修改配置文件httpd.conf 文件中的存放目錄 3、Apache是否能夠同時支持多個站點 Apache能否支持通過不同的域名訪問不同的站點 可以 做法&#xff1a;配置虛擬主機…

Public Sale【博弈】

Public Sale Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 10573 Accepted Submission(s): 6257 Problem Description 雖然不想&#xff0c;但是現實總歸是現實&#xff0c;Lele始終沒有逃過退學的命運&am…

Being a Good Boy in Spring Festival【博弈】

Being a Good Boy in Spring Festival Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8876 Accepted Submission(s): 5446 Problem Description 一年在外 父母時刻牽掛 春節回家 你能做幾天好孩子嗎 寒假里…

web安全之文件上傳漏洞攻擊與防范方法

2019獨角獸企業重金招聘Python工程師標準>>> 一、 文件上傳漏洞與WebShell的關系 文件上傳漏洞是指網絡攻擊者上傳了一個可執行的文件到服務器并執行。這里上傳的文件可以是木馬&#xff0c;病毒&#xff0c;惡意腳本或者WebShell等。這種攻擊方式是最為直接和有效的…

Rabbit and Grass【博弈】

Rabbit and Grass Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4728 Accepted Submission(s): 3592 Problem Description 大學時光是浪漫的&#xff0c;女生是浪漫的&#xff0c;圣誕更是浪漫的&#xff…

蘋果可彎曲屏幕新專利獲準,折疊iPhone最快2020年現身?

當三星Galaxy Fold、華為Mate X等折疊手機陸續問世時&#xff0c;所有果粉都想問一個問題折疊iPhone在哪里&#xff1f;就在最近有報導指出&#xff0c;蘋果獲得一項關于折疊屏幕的新專利。新專利出爐&#xff0c;但折疊iPhone還要再等等。本周二&#xff0c;美國專利與商標局授…

Brave Game【博弈】

Brave Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14813 Accepted Submission(s): 10086 Problem Description 十年前讀大學的時候&#xff0c;中國每年都要從國外引進一些電影大片&#xff0c;其中…

Google File System 學習筆記

GFS翻譯&#xff1a;https://www.cnblogs.com/cxxjohnson/p/4984309.html 一、GFS架構&#xff1a; 二、保存文件的方式 1、保存小文件&#xff1a;磁盤中分塊&#xff0c;每個block大小為1024Byte,每個文件的索引由塊號偏置組成 2、保存大文件&#xff1a;把block換成chunk,每…

探討奇技淫巧

2019獨角獸企業重金招聘Python工程師標準>>> 探討奇技淫巧 起源 在工程實踐中&#xff0c;我們常常會遇到一些奇技淫巧。所謂奇技淫巧&#xff0c;就是官方在設計或者實踐中并未想象出的代碼風格或者使用場景。其實也就是類似于 react 的 hoc,本來源自于社區&#x…

悼念512汶川大地震遇難同胞——選拔志愿者【博奕】

悼念512汶川大地震遇難同胞——選拔志愿者 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 11716 Accepted Submission(s): 7537 Problem Description 對于四川同胞遭受的災難&#xff0c;全國人民紛紛伸出援…

mall整合SpringBoot+MyBatis搭建基本骨架

本文主要講解mall整合SpringBootMyBatis搭建基本骨架&#xff0c;以商品品牌為例實現基本的CRUD操作及通過PageHelper實現分頁查詢。 mysql數據庫環境搭建 下載并安裝mysql5.7版本&#xff0c;下載地址&#xff1a;dev.mysql.com/downloads/i…設置數據庫帳號密碼&#xff1a;r…

Web框架之Django_01初識(三大主流web框架、Django安裝、Django項目創建方式及其相關配置、Django基礎三件套:HttpResponse、render、redirect)...

摘要&#xff1a; Web框架概述 Django簡介 Django項目創建 Django基礎必備三件套(HttpResponse、render、redirect) 一、Web框架概述&#xff1a; Python三大主流Web框架&#xff1a; Django&#xff1a;大而全&#xff0c;自帶了很多功能模塊&#xff0c;類似于航空母艦&am…

Bone Collector【01背包】

F - Bone Collector HDU - 2602 Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave … The bone collector had a big bag wit…

Gamma階段第八次scrum meeting

每日任務內容 隊員昨日完成任務明日要完成的任務張圓寧#91 用戶體驗與優化https://github.com/rRetr0Git/rateMyCourse/issues/91&#xff08;持續完成&#xff09;#91 用戶體驗與優化https://github.com/rRetr0Git/rateMyCourse/issues/91牛宇航#86 重置密碼的后端邏輯https:/…

【動態規劃】多重背包

問題 Q: 【動態規劃】多重背包 時間限制: 1 Sec 內存限制: 64 MB 提交: 112 解決: 49 [提交] [狀態] [討論版] [命題人:admin] 題目描述 張琪曼&#xff1a;“魔法石礦里每種魔法石的數量看起來是足夠多&#xff0c;但其實每種魔法石的數量是有限的。” 李旭琳&#xff1a;…

【動態規劃】完全背包問題

問題 O: 【動態規劃】完全背包問題 時間限制: 1 Sec 內存限制: 64 MB 提交: 151 解決: 71 [提交] [狀態] [討論版] [命題人:admin] 題目描述 話說張琪曼和李旭琳又發現了一處魔法石礦&#xff08;運氣怎么這么好&#xff1f;各種嫉妒羨慕恨啊&#xff09;&#xff0c;她們有…

springboot超級詳細的日志配置(基于logback)

前言 java web 下有好幾種日志框架&#xff0c;比如&#xff1a;logback&#xff0c;log4j&#xff0c;log4j2&#xff08;slj4f 并不是一種日志框架&#xff0c;它相當于定義了規范&#xff0c;實現了這個規范的日志框架就能夠用 slj4f 調用&#xff09;。其中性能最高的應該使…