fork download
  1. #ifdef DS
  2. #include "debug.h"
  3. #else
  4. #include<bits/stdc++.h>
  5. #define deb(...)
  6. #endif
  7. using namespace std;
  8. #define FOR(i,a,b) for (int i=a;i<=b;i++)
  9. #define FOD(i,a,b) for (int i=a;i>=b;i--)
  10. #define ALL(x) x.begin(),x.end()
  11. #define NALL(x) x.begin()+1,x.end()
  12. #define TIME "Time elapsed : "<<(double)clock()/1000<<" s"
  13. #define int long long
  14. #define vi vector<int>
  15. #define pii pair<int,int>
  16. const int MOD=1e9+7,INF=4e18;
  17. #define maxn 25
  18. int n,k,a[maxn];
  19. int sum[maxn], need_sum;
  20. bool ans = false;
  21. void Try(int i)
  22. {
  23. if (ans) return;
  24. FOR(j,1,k)
  25. if (sum[j] + a[i] <= need_sum)
  26. {
  27. sum[j] += a[i];
  28. if (i == n) ans = true;
  29. else
  30. Try(i+1);
  31. sum[j] -= a[i];
  32. }
  33. }
  34. signed main()
  35. {
  36. ios_base::sync_with_stdio(0);
  37. cin.tie(NULL);
  38. cin>>n>>k;
  39. int s = 0;
  40. FOR(i,1,n)
  41. cin>>a[i], s += a[i];
  42. if (s % k)
  43. return cout<<"0", 0;
  44. need_sum = s / k;
  45. Try(1);
  46. cout<<ans;
  47. }
  48.  
Success #stdin #stdout 0.01s 5284KB
stdin
2
5 3
2 1 4 5 6
5 3
2 1 5 5 6
stdout
Standard output is empty