Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef unsigned long long int ull;
- typedef long long int ll;
- typedef vector<int> vi;
- typedef vector<ll> vll;
- typedef vector<vi> vvi;
- typedef pair<int,int > pii;
- typedef vector< pii > vpii;
- typedef set<int> sti;
- #define sc scanf
- #define pf printf
- #define sci(n) scanf("%d",&n)
- #define scii(n,m) scanf("%d %d",&n,&m)
- #define scl(n) scanf("%lld",&n)
- #define scd(n) scanf("%lf",&n)
- #define scs(s) scanf("%s",s)
- #define pfi(n) printf("%d",n)
- #define pfl(n) printf("%lld",n)
- #define pff(n) cout<<n
- #define line printf("\n")
- #define spc printf(" ")
- #define clr(a,x) memset(a,x,sizeof(a))
- #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
- #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
- #define cspf(i) printf("Case %d: ", i)
- #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
- #define pb push_back
- #define mp make_pair
- #define ff first
- #define ss second
- #define all(v) v.begin(),v.end()
- #define rall(v) v.rbegin(),v.rend()
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
- /// Constants
- #define eps 1e-9
- #define PI acos(-1.0) // 3.1415926535897932
- #define MAX (int)1e9
- ll GCD(ll a, ll b) { return b == 0 ? a : GCD(b , a % b); }
- ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
- int a[1005];
- int n,k;
- bool kth(int val)
- {
- int kt=1,temp=0;
- loop(i,1,n){
- temp+=a[i];
- if(a[i]>val) return false;
- if(temp>val){
- kt++;
- temp=a[i];
- }
- }
- if(kt>k) return false;
- return true;
- }
- int Binary(int lo,int hi)
- {
- if(lo>hi) return MAX;
- int mid = (lo+hi)/2;
- //printf("%d\n", mid);
- if(kth(mid)) return min(mid,Binary(lo,mid-1));
- return Binary(mid+1,hi);
- }
- void Display(int val)
- {
- int i=1,j=1,temp=0;
- printf("%d\n", val);
- while(i<=n){
- int x = n-i;
- int y = k-j;
- if(x<y){
- if(temp) printf("%d\n", temp);
- temp = 0;
- loop(b,i,n) printf("%d\n", a[b]);
- break;
- }
- if(temp+a[i]>val){
- printf("%d\n", temp);
- temp=a[i];
- j++;
- }
- else temp+=a[i];
- i++;
- }
- if(temp) printf("%d\n", temp);
- }
- int main()
- {
- read();
- write();
- int t;
- sci(t);
- loop(ca,1,t){
- scii(n,k);
- n++;
- k++;
- loop(i,1,n) sci(a[i]);
- cspf(ca);
- Display(Binary(1,(int)1e8));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement