Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5. typedef double db;
  6. int main(){
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0); cout.tie(0);
  9. ll n,a[100000],check[4],i,j,dem=0;
  10. cin>>n;
  11. for(i=0;i<n;i++){
  12. cin>>a[i];
  13. check[a[i]]++;
  14. }
  15. check[2]+=check[1];
  16. for(i=0;i<check[1];i++){
  17. if(a[i]!=1)
  18. for(j=check[1];j<n;j++){
  19. if(a[j]==1){
  20. dem++;
  21. swap(a[i],a[j]);
  22. break;
  23. }
  24. }
  25. }
  26.  
  27. for(i=check[1];i<check[2];i++){
  28. if(a[i]!=2)
  29. for(j=check[2];j<n;j++){
  30. if(a[j]==2){
  31. dem++;
  32. swap(a[i],a[j]);
  33. break;
  34. }
  35. }
  36. }
  37. cout<<dem;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement