35657

Untitled

Jun 6th, 2024
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4.  
  5.  
  6. int main() {
  7.     setlocale(LC_ALL, "ru");
  8.  
  9.     std::ifstream fin("input.txt");
  10.  
  11.     std::vector<int> greed(1001);
  12.    
  13.     int size, value, count = 0;
  14.  
  15.     fin >> size;
  16.  
  17.     for (int i = 0; i < size; i++) {
  18.         fin >> value;
  19.         greed[value]++;
  20.     }
  21.  
  22.     fin >> size;
  23.  
  24.     for (int i = 0; i < size; i++) {
  25.         fin >> value;
  26.         if (greed[value]) {
  27.             count++;
  28.             greed[value]--;
  29.         }
  30.         else {
  31.             for (int j = value - 1; j > 0; j--) {
  32.                 if (greed[j]) {
  33.                     count++;
  34.                     greed[j]--;
  35.                     break;
  36.                 }
  37.             }
  38.         }
  39.     }
  40.  
  41.     std::cout << count;
  42. }
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment