Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef double db;
- int main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0); cout.tie(0);
- ll n,a[100000],check[4],i,j,dem=0;
- cin>>n;
- for(i=0;i<n;i++){
- cin>>a[i];
- check[a[i]]++;
- }
- check[2]+=check[1];
- for(i=0;i<check[1];i++){
- if(a[i]!=1)
- for(j=check[1];j<n;j++){
- if(a[j]==1){
- dem++;
- swap(a[i],a[j]);
- break;
- }
- }
- }
- for(i=check[1];i<check[2];i++){
- if(a[i]!=2)
- for(j=check[2];j<n;j++){
- if(a[j]==2){
- dem++;
- swap(a[i],a[j]);
- break;
- }
- }
- }
- cout<<dem;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement