Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- int main()
- {
- ifstream in;
- ofstream out;
- in.open( "cardgame.in" );
- out.open( "cardgame.out" );
- int n;
- in >> n;
- vector<int> elsie(n);
- vector<int> bessie(2*n, 0); // -1 = doesn't have, 0 = unused, 1 = lost, 2 = won
- for( int i = 0; i < n; i++ )
- {
- in >> elsie[i];
- bessie[--elsie[i]] = -1;
- }
- vector<int> lower;
- vector<int> higher;
- for( int i = 0, k = 0; i < 2*n; i++ )
- {
- if( bessie[i] == 0 )
- {
- if( k < n/2 )
- {
- lower.push_back( i );
- k++;
- } else
- higher.push_back( i );
- }
- }
- for( int i = 0; i < n/2; i++ )
- {
- if( elsie[i] > higher.back() )
- {
- bessie[higher.front()] = 1;
- higher.erase( higher.begin() );
- } else
- {
- int j = 0;
- for( j = 0; j < higher.size() && higher.at( j ) < elsie[i]; j++ );
- bessie[higher.at( j )] = 2;
- higher.erase( higher.begin()+j );
- }
- }
- for( int i = n/2; i < n; i++ )
- {
- if( elsie[i] < lower.front() )
- {
- bessie[lower.back()] = 1;
- lower.erase( lower.end()-1 );
- } else
- {
- int j = 0;
- for( j = lower.size()-1; j >= 0 && lower.at( j ) > elsie[i]; j-- );
- bessie[lower.at( j )] = 2;
- lower.erase( lower.begin()+j );
- }
- }
- int ans = 0;
- for( int i = 0; i < 2*n; i++ )
- if( bessie[i] == 2 )
- ans++;
- out << ans << endl;
- in.close();
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement