Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n, max, up, down = 0, counter = 0, left;
- scanf("%i%i",&max,&n);
- int tablica[n];
- for(int i=0;i<n;i++)scanf("%i",&tablica[i]);
- sort(tablica, tablica+n);
- up = n-1; left = n;
- while(left>1){
- if(tablica[down]+tablica[up]<=max){
- counter++;
- up--;
- down++;
- left -= 2;
- }
- else{
- counter++;
- up--;
- left--;
- }
- }
- if(left==1)counter++;
- printf("%i",counter);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement