Skip to content

Commit

Permalink
Create traveling_options
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitcn authored Sep 30, 2018
1 parent da7b347 commit b1cfdf5
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Directi/traveling_options
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
int t , temp ;
cin>>t;
vector<ll> v;
for(int i=0;i<t;i++)
{ cin>>temp;
v.push_back(temp);
}
sort(v.begin(),v.end());
string bb;
cin>>bb;
int count=0;
if(bb=="NIL")
cout<<"0";
else
{
int b=stoi(bb);
for(int i=0;i<t;i++)
{ if(v[i]>b)
{ break; }
else if(v[i]<=b)
{count++;b-=v[i];}

}

if(count==0)
cout<<"-1";
else
cout<<count;
}




return 0;
}

0 comments on commit b1cfdf5

Please sign in to comment.