Codeforces 489B - BerSU Ball Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int i,n,m,j,c=0;
- cin>>n;
- int a[n];
- for(int i=0; i<n; i++)
- cin>>a[i];
- sort(a,a+n);
- cin>>m;
- int b[m];
- for(int i=0; i<m; i++)
- cin>>b[i];
- sort(b,b+m);
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<m; j++)
- {
- if(abs(a[i]-b[j])<=1)
- {
- b[j]=10001;
- c++;
- i++;
- }
- }
- }
- cout<<c<<endl;
- }
No comments