Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize ("O3")
- #pragma GCC target ("sse4")
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef pair<string,int> psi;
- typedef vector<int> vi;
- typedef vector<string> vs;
- typedef vector<ll> vll;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<string>> vvs;
- typedef vector<vector<ll>> vvll;
- #define FOR(i, a, b) for (auto i=a; i<=(b); i++)
- #define FORd(i,b,a) for (int i =b; i >= a; i--)
- #define sz(x) (int)(x).size()
- #define mp make_pair
- #define pb push_back
- #define f first
- #define s second
- #define ins insert
- const int MOD = 1000000007;
- //type functions here
- int ans;
- void ptns(vi &v,int prt,int idx,int max_sum)
- {
- int sum=0;
- if(idx>=sz(v))
- return;
- if(prt==1)
- {
- while(idx!=sz(v))
- {
- sum+=v[idx];
- idx++;
- }
- max_sum=max(max_sum,sum);
- ans=min(ans,max_sum);
- return;
- }
- FOR(i,idx,sz(v)-prt)//important
- {
- sum+=v[i];
- max_sum=max(sum,max_sum);
- ptns(v,prt-1,i+1,max_sum);
- }
- }
- int main() {
- int tc;
- cin>>tc;
- FOR(i,1,tc)
- {
- ans=INT_MAX;
- int size,prt;
- vi v;
- cin>>size>>prt;
- FOR(j,1,size)
- {
- int temp;
- cin>>temp;
- v.pb(temp);
- }
- ptns(v,prt,0,INT_MIN);
- cout<<ans<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement