Advertisement
mickypinata

PROG-T1080: Tri Again

Jun 12th, 2021
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 3e4;
  5.  
  6. int sticks[N + 10];
  7.  
  8. int main(){
  9.  
  10.     int nStick;
  11.     scanf("%d", &nStick);
  12.     if(nStick < 3){
  13.         cout << nStick;
  14.         return 0;
  15.     }
  16.     for(int i = 1; i <= nStick; ++i){
  17.         scanf("%d", &sticks[i]);
  18.     }
  19.     sort(sticks + 1, sticks + nStick + 1);
  20.  
  21.     int lastIdx = lower_bound(sticks + 1, sticks + nStick + 1, sticks[1] + sticks[2]) - sticks;
  22.     int mx = 2;
  23.     for(int i = 1; i <= nStick - 2; ++i){
  24.         while(lastIdx <= nStick && sticks[i] + sticks[i + 1] > sticks[lastIdx]){
  25.             ++lastIdx;
  26.         }
  27.         mx = max(mx, lastIdx - i);
  28.         if(lastIdx > nStick){
  29.             break;
  30.         }
  31.     }
  32.     cout << mx;
  33.  
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement