Lazy Salesman Solution
Codechef February Cook-Off 2022
Problem Code : HOLIDAYS
Solution :
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;
void solve()
{
ll n, w;
cin >> n >> w;
ll a[n];
for (ll i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a, a + n);
ll total = 0, day = 0;
for (ll i = n - 1; i >= 0; i--)
{
total += a[i];
day++;
if (total >= w)
{
break;
}
}
cout << n - day << "\n";
}
int main()
{
ll t;
cin >> t;
while (t--)
{
solve();
}
}
Comments
Post a Comment