#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int inf = 2e9;
void print(vector<int> a, int n) {
for (int i=0; i<n; i++) {
cout<<a[i]<<" ";
}
cout<<endl;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, m;
cin>>n>>m;
vector<pair<int,int>> a(n);
for (int i=0; i<n; i++) {
cin>>a[i].first>>a[i].second;
}
vector<int> w(m);
for (int i=0; i<m; i++) {
cin>>w[i];
}
sort(w.begin(),w.end());
vector<vector<int>> items(m);
for (auto p: a) {
int size = p.first;
int value = p.second;
int idx = std::lower_bound(w.begin(),w.end(),size)-w.begin();
if (idx==m) {
continue;
}
items[idx].push_back(value);
}
vector<int> dp(m+10, -inf); //dp[i]: min value of i+1 items
int mx = -1;
auto insert = [&](int x, int ub) {
int lo = -1;
int hi = m-1;
while (hi-lo>1) {
int mid=(lo+hi)/2;
if (dp[mid]<x) { // leftmost smaller
hi = mid;
} else {
lo = mid;
}
}
if (hi<=ub) {
dp[hi] = x;
mx = max(mx, hi);
}
//print(dp, m);
};
int ans = 0;
for (int i=m-1; i>=0; i--) {
for (int val: items[i]) {
insert(val, m-i-1);
}
ans = max(ans, mx+1);
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |