#include <bits/stdc++.h>
using namespace std;
struct painting {
int size, value;
};
struct AIB {
int n;
vector<int> aib;
void init( int _n ) {
n = _n;
aib.clear();
aib.resize( n + 1 );
}
void update( int i, int x ) {
while ( i <= n ) {
aib[i] = max( aib[i], x );
i += (i & -i);
}
}
int query( int i ) {
int s = 0;
while ( i > 0 ) {
s = max( s, aib[i] );
i -= (i & -i);
}
return s;
}
};
const int MAX_N = 1e5;
const int MAX_M = 1e5;
painting paintings[MAX_N + 1];
int frames[MAX_M + 1];
int dp[MAX_N + 1];
AIB dps;
map<int, int> normal;
int main() {
ios_base::sync_with_stdio( false );
cin.tie( nullptr );
int n, m;
cin >> n >> m;
for ( int i = 1; i <= n; i++ ) {
cin >> paintings[i].size >> paintings[i].value;
normal[paintings[i].value] = 1;
}
for ( int i = 1; i <= m; i++ )
cin >> frames[i];
sort( paintings + 1, paintings + 1 + n, []( painting a, painting b ) {
if ( a.size == b.size )
return a.value > b.value;
return a.size > b.size;
} );
sort( frames + 1, frames + 1 + m );
int maxValue = 0;
for ( auto p: normal )
normal[p.first] = ++maxValue;
for ( int i = 1; i <= n; i++ )
paintings[i].value = normal[paintings[i].value];
int j = m;
dps.init( maxValue );
for ( int i = 1; i <= n; i++ ) {
while ( j >= 1 && frames[j] >= paintings[i].size )
j--;
dp[i] = min( m - j, 1 + dps.query( maxValue + 1 - paintings[i].value ) );
dps.update( maxValue + 1 - paintings[i].value, dp[i] );
//printf( "%d (%d %d) %d: %d\n", i, paintings[i].size, paintings[i].value, m - j, dp[i] );
}
cout << dps.query( maxValue ) << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |