Monthly Expense
Time Limit: 2000MS |
|
Memory Limit: 65536K |
Total Submissions: 16796 |
|
Accepted: 6660 |
Description
Farmer John is an astounding Accounting wizard and have 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'll 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 the these fajomonths contains a set of 1 or more consecutive days. Every day was 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
101
400
Sample Output
500
Similar to the previous question is to choose m consecutive day to make fajmonth less than or equal to two points of the answer
The AC code is as follows:
POJ 3273 Monthly Expense////Created by Taosama on 2015-04-24//Copyright (c) Taosama.
All rights reserved. #include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include < cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include &
lt;queue> #include <string> #include <set> #include <vector> using namespace std;
const int INF = 0X3F3F3F3F;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
int n, M, A[n];
BOOL Check (int x) {int last = 0;
for (int i = 1; I <= m; ++i) {int idx = last + 1, sum = A[idx];
while (IDX <= n && sum < x) {++idx;
Sum + = A[idx];
} if (idx = = n + 1) return false;
last = idx-1;
} return true; } int main () {#ifdef LOCAL freopen ("In.txt", "R", stdin);//Freopen ("OUT.txt", "w", stdout); #endif Ios_base::sy Nc_with_stdIo (0);
CIN >> n >> m;
for (int i = 1; I <= n; ++i) {cin >> a[i];
} int l = 0, r = 1e9 + 1;
while (L + 1 < r) {int mid = 0LL + L + R >> 1;
if (check (mid)) L = mid;
else R = Mid;
} cout << l << ' \ n ';
return 0;
}