#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// Surat ma'lumotlari uchun struktura
struct Picture {
int size, value;
};
// Suratlarni qiymati (value) bo'yicha tartiblash uchun funksiya
bool comparePictures(const Picture& a, const Picture& b) {
if (a.value != b.value) return a.value < b.value;
return a.size < b.size;
}
int main() {
// Kiritish-chiqarishni tezlashtirish
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
cin >> N >> M;
vector<Picture> pics(N);
for (int i = 0; i < N; i++) {
cin >> pics[i].size >> pics[i].value;
}
vector<int> frames(M);
for (int i = 0; i < M; i++) {
cin >> frames[i];
}
// 1. Suratlarni qiymati bo'yicha tartiblaymiz
sort(pics.begin(), pics.end(), comparePictures);
// 2. Ramkalarni o'lchami bo'yicha tartiblaymiz
sort(frames.begin(), frames.end());
int ans = 0;
int frame_ptr = M - 1; // Eng katta ramkadan boshlaymiz
// 3. Suratlarni eng qimmatidan boshlab tekshiramiz
for (int i = N - 1; i >= 0; i--) {
// Agar ramkalar qolgan bo'lsa va surat ramkaga sig'sa
if (frame_ptr >= 0 && pics[i].size <= frames[frame_ptr]) {
ans++;
frame_ptr--; // Bu ramka band bo'ldi, endi undan kichigini ko'ramiz
}
}
cout << ans << endl;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |