Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int n;
- int t;
- int tm[100000];
- cin>>n;
- cin>>t;
- for(int i=0;i<n;i++){
- cin>>tm[i];
- }
- int template1;
- for (int i = 0; i < n - 1; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- if (tm[i] > tm[j])
- {
- template1 = tm[i];
- tm[i] = tm[j];
- tm[j] = template1;
- }
- }
- }
- int totaltime = 0;
- //int counter = 0;
- //while (totaltime <= t)
- //{
- // if (counter <n)
- // {
- // totaltime = totaltime + tm[counter];
- // counter++;
- // }
- // else
- // {
- // break;
- // }
- //}
- //cout<<"\nSorted";
- /*for(int i=0;i<n;i++){
- cout<<tm[i]<<" ";
- }
- cout<<endl;
- */
- int packet=0;
- int counter = 0;
- for (int i = 0; i < n; i++)
- {
- //packet = totaltime;
- totaltime = totaltime + tm[i];
- if (totaltime<=t)
- {
- counter++;
- }
- else{
- break;
- }
- }
- //cout<<"Total Time"<<totaltime<<endl;
- cout<<counter;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement