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
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int n,i,j,s=0,tc=0,ans=0;
- cin>>n;
- int a[n+9];
- for(i=0; i<n; i++)
- cin>>a[i];
- sort(a,a+n);
- for(s=1; s<=100; s++)
- {
- tc=0;
- for(i=0,j=n-1; i<j;)
- {
- if(a[i]+a[j]>s)j--;
- else if(a[i]+a[j]<s)i++;
- else
- {
- tc++;
- j--,i++;
- }
- }
- ans=max(tc,ans);
- }
- cout<<ans<<endl;
- }
- }
No comments