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 925 (Div. 3) 1931D. Divisible Pairs Solution

        Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

    Powered by Blogger.