Codeforces 489B - BerSU Ball Solution

 Solution in C++:

///**********ALLAH IS ALMIGHTY************///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh  

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int i,n,m,j,c=0;
  6. cin>>n;
  7. int a[n];
  8. for(int i=0; i<n; i++)
  9. cin>>a[i];
  10. sort(a,a+n);
  11. cin>>m;
  12. int b[m];
  13. for(int i=0; i<m; i++)
  14. cin>>b[i];
  15. sort(b,b+m);
  16. for(int i=0; i<n; i++)
  17. {
  18. for(int j=0; j<m; j++)
  19. {
  20. if(abs(a[i]-b[j])<=1)
  21. {
  22. b[j]=10001;
  23. c++;
  24. i++;
  25. }
  26. }
  27. }
  28. cout<<c<<endl;
  29. }

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.