We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 84cd178 commit 6f68fe8Copy full SHA for 6f68fe8
CSES/Array Division.cpp
@@ -0,0 +1,30 @@
1
+#include <bits/stdc++.h>
2
+using namespace std;
3
+
4
+#define ll long long
5
6
+int main(){
7
+ int n, k;
8
+ cin>>n>>k;
9
+ int x[n];
10
+ for(int i=0; i<n; ++i)
11
+ cin>>x[i];
12
+ ll lb=*max_element(x, x+n), rb=1e18;
13
+ while(lb<rb){
14
+ ll mb=(lb+rb)/2;
15
+ int c=0;
16
+ ll sum=0;
17
+ for(int i=0; i<n; ++i){
18
+ if(sum+x[i]>mb){
19
+ ++c;
20
+ sum=0;
21
+ }
22
+ sum+=x[i];
23
24
+ if(c>=k)
25
+ lb=mb+1;
26
+ else
27
+ rb=mb;
28
29
+ cout<<lb;
30
+}
0 commit comments