Skip to content

Commit

Permalink
Mark and Toys
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranjal authored Mar 7, 2017
1 parent 83f55b2 commit d4deb8f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions MarkAndToys.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;



int main()
{
long long n, k; cin >> n >> k;
vector<int> prices;
for(int i = 0; i < n; i++)
{
int p; cin >> p;
prices.push_back(p);
}

int answer = 0;

// Write the code for computing the final answer using n,k,prices
sort(prices.begin(), prices.end());

int i = 0;

while(i < n){
if(k < prices[i]){
break;
}
k = k - prices[i];
answer++;
i++;
}

cout << answer << endl;

return 0;
}

0 comments on commit d4deb8f

Please sign in to comment.