Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,k,p,wynik;
  4. bool czy;
  5. vector<pair <int,int> > V1,V2;
  6. int T1[42],T2[42];
  7. int main(){
  8. cin>>n>>k;
  9. for(int i=0;i<n/2;i++){
  10. cin>>T1[i];
  11. }
  12. V1.push_back(make_pair(0,0));
  13. V2.push_back(make_pair(0,0));
  14. for(int i=0;i<n-n/2;i++){
  15. cin>>T2[i];
  16. }
  17. for(int i=0;i<n/2;i++){
  18. for(int j=V1.size()-1;j>0;j--){
  19. V1.push_back(make_pair(T1[i]+V1[j].first,V1[j].second+1));
  20. }
  21.  
  22. }
  23. for(int i=0;i<n-n/2;i++){
  24. for(int j=V2.size()-1;j>0;j--){
  25. V2.push_back(make_pair(T2[i]+V2[j].first,V2[j].second+1));
  26. }
  27.  
  28. }
  29. sort(V2.begin(),V2.end());
  30. for(int i=V1.size()-1;i>0;i--){
  31. vector<pair<int,int> >::iterator temp=lower_bound(V2.begin(),V2.end(),k-V1[i].first);
  32. if(V2[temp].first+V1[i].first==k and V2[temp].second+V1[i].second<wynik){ wynik=V2[temp].second+V1[i].second; czy=1;}
  33. }
  34. if(czy==1) cout<<wynik;
  35. else cout<<"NIE";
  36. //return 0;
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement