Advertisement
Sabab

exmrush

Feb 16th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6.  int n;
  7. int t;
  8. int tm[100000];
  9. cin>>n;
  10. cin>>t;
  11.  
  12.  
  13. for(int i=0;i<n;i++){
  14.  
  15.     cin>>tm[i];
  16. }
  17.  
  18.  
  19. int template1;
  20.             for (int i = 0; i < n - 1; i++)
  21.             {
  22.  
  23.                 for (int j = i + 1; j < n; j++)
  24.                 {
  25.                     if (tm[i] > tm[j])
  26.                     {
  27.                         template1 = tm[i];
  28.                         tm[i] = tm[j];
  29.                         tm[j] = template1;
  30.  
  31.                     }
  32.  
  33.                 }
  34.             }
  35.  
  36.  
  37.  
  38.             int totaltime = 0;
  39.             //int counter = 0;
  40.             //while (totaltime <= t)
  41.             //{
  42.             //    if (counter <n)
  43.             //    {
  44.  
  45.             //        totaltime = totaltime + tm[counter];
  46.             //        counter++;
  47.  
  48.             //    }
  49.  
  50.             //    else
  51.             //    {
  52.             //        break;
  53.             //    }
  54.  
  55.             //}
  56.  
  57.             //cout<<"\nSorted";
  58.  
  59.             /*for(int i=0;i<n;i++){
  60.                 cout<<tm[i]<<" ";
  61.             }
  62.             cout<<endl;
  63. */
  64.             int packet=0;
  65.             int counter = 0;
  66.             for (int i = 0; i < n; i++)
  67.             {
  68.                 //packet = totaltime;
  69.  
  70.                 totaltime = totaltime + tm[i];
  71.  
  72.  
  73.                 if (totaltime<=t)
  74.                 {
  75.                     counter++;
  76.  
  77.                 }
  78.  
  79.                 else{
  80.                     break;
  81.                 }
  82.  
  83.             }
  84.  
  85.             //cout<<"Total Time"<<totaltime<<endl;
  86.             cout<<counter;
  87.  
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement