Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n,k,p,wynik;
- bool czy;
- vector<pair <int,int> > V1,V2;
- int T1[42],T2[42];
- int main(){
- cin>>n>>k;
- for(int i=0;i<n/2;i++){
- cin>>T1[i];
- }
- V1.push_back(make_pair(0,0));
- V2.push_back(make_pair(0,0));
- for(int i=0;i<n-n/2;i++){
- cin>>T2[i];
- }
- for(int i=0;i<n/2;i++){
- for(int j=V1.size()-1;j>0;j--){
- V1.push_back(make_pair(T1[i]+V1[j].first,V1[j].second+1));
- }
- }
- for(int i=0;i<n-n/2;i++){
- for(int j=V2.size()-1;j>0;j--){
- V2.push_back(make_pair(T2[i]+V2[j].first,V2[j].second+1));
- }
- }
- sort(V2.begin(),V2.end());
- for(int i=V1.size()-1;i>0;i--){
- vector<pair<int,int> >::iterator temp=lower_bound(V2.begin(),V2.end(),k-V1[i].first);
- 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;}
- }
- if(czy==1) cout<<wynik;
- else cout<<"NIE";
- //return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement