Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Smalllest subarray wiith sum greater than x
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,k; cin>>n>>k; vector<int>v(n); for(int i=0;i<n;i++) cin>>v[i]; int res=1e6; int left=0; int val=0; for(int i=0;i<n;i++) { val+=v[i]; while(val>k) { res=min(res,i-left+1); val=val-v[left]; left++; } } if(res!=1e6) cout<<res<<endl; else { cout<<0<<endl; } } }
run
|
edit
|
history
|
help
0
Exempel 1
Set of intervals.
prototype match
Test 17(2021)
Aplicatie-Proiect
Elevator 2
water drop/ water land
MyStack
顺序表的实现——静态分配
test yield