jakaria_hossain

codeforce - DIY Wooden Ladder

Jul 23rd, 2019
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. while(t--)
  8. {
  9. int n;
  10. cin>>n;
  11. int ara[n+1];
  12. for(int i=0;i<n;i++)
  13. {
  14. cin>>ara[i];
  15. }
  16. sort(ara,ara+n);
  17. int ans=ara[n-2]-1;
  18. ans=min(n-2,ans);
  19. cout<<ans<<endl;
  20. }
  21. }
RAW Paste Data