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

    RESTful APIs with CRUD Operations in Laravel 12| (2025)

      RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

    Powered by Blogger.