SHOI2015
Description, inventor of the signal-growth instrument, SHTSC also disclosed his new invention: Automatic Brush machine-a mysterious device that can automatically ac the subject. The way to brush the problem automatically is very simple: first will immediately get the correct practice of the topic, and then start to write the program, every second, the auto-brush machine code Generation module will have two possible results: a. wrote x lines of code. B. In a bad mood, delete the previously written Y line code. (if Y is greater than the current code length it is equivalent to deleting all.) For each OJ, there is a fixed length of n>0. Once the auto-brush machine accumulates more than n lines of code at the end of a second, it automatically submits and AC the problem, and then creates a new file to start writing the next question. SHTSC on a OJ to run a day of automatic brush machine, get a lot of write code about the log information. He suddenly found himself without a record of what the OJ N was. Fortunately, he knew by his rank on the OJ that the machine had cut the K-question altogether. I want you to calculate the possible minimum and maximum values for n.
Input first line two integer l,k, indicating that the brush machine log a total of L line, altogether has cut k question. The second row is an integer of L, X1...XL. Xi>=0 indicates that the XI line code is written. Xi<0 indicates that the-XI line code for this problem has been deleted. 1<=l,k<=100000,|xi|<=10^9
Output two number A, B. Represents the minimum and maximum possible values for N. If there is no such n then output-1.
Sample Input4 2
2
5
-3
9
Sample Output3 7
Example 1: If n=2 then brush the machine will cut off 3 questions. But if the n>7 brush machine can only cut 1 questions. Consider what happened to n=4.
The first second: Brush the machine wrote 2 lines.
Second second: Brush the machine and wrote 5 lines, a total of 7 lines, submitted, confident AC.
The third second: Brush the machine deleted 3 lines, a total of 0 lines.
Four seconds: Brush the machine wrote 9 lines, a total of 9 lines, submitted, confident AC.
There was a total of AC two questions.
Positive solution: Two-point answer
Problem Solving Report:
Hi sense of the topic, I also want to have automatic brush problem machine. If the direct judgment of the words seems to be difficult to do, but only need a maximum minimum value, we consider to transform into a decision-making problem
Two-point answer, the length of the two-point question, and then update the answer in either way.
1 //It's made by jump~2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> - #ifdef WIN32 - #defineOT "%i64d" the #else - #defineOT "%lld" - #endif - using namespacestd; +typedefLong LongLL; - Const intMAXN =100011; + LL inf; A LL ans1,ans2; at intm,k; - LL A[MAXN]; - LL l,r; - -InlineintGetint () - { in intw=0, q=0; - CharC=GetChar (); to while((c<'0'|| C>'9') && c!='-') c=GetChar (); + if(c=='-') q=1, c=GetChar (); - while(c>='0'&& c<='9') w=w*Ten+c-'0', c=GetChar (); the returnQ? -w:w; * } $ Panax Notoginseng inline LL getlong () - { theLL w=0, q=0; + CharC=GetChar (); A while((c<'0'|| C>'9') && c!='-') c=GetChar (); the if(c=='-') q=1, c=GetChar (); + while(c>='0'&& c<='9') w=w*Ten+c-'0', c=GetChar (); - returnQ? -w:w; $ } $ - inline ll Check (ll x) { -LL cnt=0; theLL now=0; - for(intI=1; i<=m;i++){Wuyi if(a[i]+now>0) Now+=a[i];Elsenow=0; the if(now>=x) { -cnt++; Wunow=0;//Clear 0!!! - //if (cnt>=k) return true; About } $ } - returnCNT; - } - A intMain () + { theM=getint (); k=getint (); -inf=1; for(intI=1; i<= -; i++) inf*=2; $ for(intI=1; i<=m;i++) a[i]=Getlong (); theL=1, r=inf; the while(l<=R) { theLL mid= (l+r) >>1; the if(Check (mid) >k) l=mid+1, ans1=mid; - Elser=mid-1; in } the theL=1, r=inf; About while(l<=r) { theLL mid= (l+r) >>1; the if(Check (mid) <k) r=mid-1, ans2=mid; the ElseL=mid+1; + } -ans1++; ans2--; the if(Check (ans1) ==k && Check (ans2) ==k) printf (OT" "ot,ans1,ans2);Bayi Elseprintf"-1"); the return 0; the}
BZOJ4590 Automatic Brush problem machine