Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
chocolate Distribution Problem
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,k; cin>>n; vector<int>v(n); for(int i=0;i<n;i++) { cin>>v[i]; } cin>>k; sort(v.begin(),v.end()); int i=0; int j=i; int cur_sum=0; int res=1e6; while(i<=n-k) { j=i+k-1; res=min(res,v[j]-v[i]); i++; } cout<<res<<endl; } } /* 2 8 3 4 1 9 56 7 9 12 1 3 4 7 9 9 12 56 5 */
run
|
edit
|
history
|
help
0
Subarray with 0 sum
use of assert to check a particular situation! (throws error)
Intersected Rectangles
sgfsfdgsfd
<string> Indirect include of <errno.h> with gcc
UB mutex lock
single_digit
Listas enlazadas - k-esimo elemento
test
11aa11