Advertisement
encoree1996

Untitled

Nov 10th, 2013
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n, max, up, down = 0, counter = 0, left;
  9.     scanf("%i%i",&max,&n);
  10.     int tablica[n];
  11.     for(int i=0;i<n;i++)scanf("%i",&tablica[i]);
  12.     sort(tablica, tablica+n);
  13.     up = n-1; left = n;
  14.     while(left>1){
  15.         if(tablica[down]+tablica[up]<=max){
  16.             counter++;
  17.             up--;
  18.             down++;
  19.             left -= 2;
  20.         }
  21.         else{
  22.             counter++;
  23.             up--;
  24.             left--;
  25.         }
  26.     }
  27.     if(left==1)counter++;
  28.     printf("%i",counter);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement