➤ Problem Link : 1296D. Fight with Monsters
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll n,a,b,k,val,cnt,pwr;
cin>>n>>a>>b>>k;
pair<ll,ll> arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i].second;
arr[i].first = 0;
pwr=arr[i].second;
if(pwr <= a+b )
val = pwr-a;
else
{
cnt = pwr/(a+b);
cnt=cnt*(a+b);
if(cnt==pwr)
cnt-=(a+b);
cnt += a;
val = pwr - cnt ;
}
if(val <= 0)
continue;
if(val%a==0)
arr[i].first = val/a ;
else
arr[i].first = val/a + 1 ;
}
// for(int i=0;i<n;i++)
// cout<<arr[i].first<<" ";
sort(arr,arr+n);
int ans=0;
cnt=0;
for(int i=0;i<n;i++)
{
cnt+=arr[i].first;
if(cnt>k)
break;
ans++;
}
cout<<ans;
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
