# CFR 416 C. Booking System ( Greedy )

Problem - 416C - Codeforces

```int N;
vi C, P;
int K;
vi R;

void init(){
cin >> N;
C = P = vi( N );
for( int i = 0; i < N; ++i )
cin >> C[ i ] >> P[ i ];
cin >> K;
R = vi( K );
for( int i = 0; i < K; ++i )
cin >> R[ i ];
}

typedef tuple< int, int, int > tiii;
vector< tiii > request;

void preprocess(){
for( int i = 0; i < N; ++i )
request.emplace_back( P[ i ], C[ i ], i );
sort( request.begin(), request.end(), greater< tiii >() );
}

void solve(){
int profit = 0;
vp acreq;
vi vis( K );
for( int i = 0; i < N; ++i ){
int val, size, id;
tie( val, size, id ) = request[ i ];
int tsz = INF, tid = -1;
for( int j = 0; j < K; ++j )
if( not vis[ j ] and R[ j ] >= size )
if( upmin( tsz, R[ j ] ) )
tid = j;
if( tid == -1 )
continue;
profit += val;
vis[ tid ] = 1;
acreq.push_back( pii( id, tid ) );
}
cout << ( int ) acreq.size() << " " << profit << endl;
for( int i = 0; i < acreq.size(); ++i )
cout << acreq[ i ].first + 1 << " " << acreq[ i ].second + 1 << endl;
}
```