➤ Problem Link : 913D. Too Easy Problems
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pp pair<ll,ll> #define mp make_pair #define pb push_back #define ppp pair<pp,ll> ll n,t; vector<ppp> arr; bool func(int v) { int cnt=0; ll tim=0; for(int i=0;i<n;i++) { if(cnt >= v) return 1; if(arr[i].first.second>=v) { tim+=arr[i].first.first; if(tim>t) return 0; cnt++; } } if(cnt>=v) return 1; return 0; } void fun(int v) { int cnt=0; for(int i=0;i<n;i++) { if(cnt >= v) return ; if(arr[i].first.second>=v) { cout<<arr[i].second<<" "; cnt++; } } return ; } int main() { ll a,b; cin>>n>>t; arr.clear(); for(int i=0;i<n;i++) { cin>>a>>b; arr.pb(mp(mp(b,a),i+1)); } sort(arr.begin(),arr.end()); ll low=0,mid,high=n; while(low<high) { mid=low+(high-low+1)/2; if(func(mid)) low=mid; else high=mid-1; } cout<<high<<"\n"<<high<<"\n"; fun(high); }
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!!