Codeforces 1399C. Boats Competition Solution

  Solution in C++:    

///La ilaha illellahu muhammadur rasulullah

///******Bismillahir-Rahmanir-Rahim******///

///Abul Hasnat  Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh

    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,i,j,s=0,tc=0,ans=0;
    10. cin>>n;
    11. int a[n+9];
    12. for(i=0; i<n; i++)
    13. cin>>a[i];
    14. sort(a,a+n);
    15. for(s=1; s<=100; s++)
    16. {
    17. tc=0;
    18. for(i=0,j=n-1; i<j;)
    19. {
    20. if(a[i]+a[j]>s)j--;
    21. else if(a[i]+a[j]<s)i++;
    22. else
    23. {
    24. tc++;
    25. j--,i++;
    26. }
    27.  
    28. }
    29. ans=max(tc,ans);
    30. }
    31. cout<<ans<<endl;
    32. }
    33. }

    No comments

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

      Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

    Powered by Blogger.