D_L3

Най-продаван артикул

Jan 26th, 2024
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <deque>
  7. #include <queue>
  8. #include <stack>
  9. #include <string>
  10. #include <bitset>
  11. #include <cstdio>
  12. #include <limits>
  13. #include <vector>
  14. #include <climits>
  15. #include <cstring>
  16. #include <cstdlib>
  17. #include <fstream>
  18. #include <numeric>
  19. #include <sstream>
  20. #include <iostream>
  21. #include <algorithm>
  22. #include <unordered_map>
  23.  
  24. using namespace std;
  25.  
  26.  
  27.  
  28. int main() {
  29.     int n, a, b, t, q;
  30.     cin >> n;
  31.    
  32.     vector<pair<int, int>> products; //id time
  33.     unordered_map<int, int> quality; //id count
  34.    
  35.     map<int, int> answears; // time, most sell id
  36.    
  37.     int max = 0;
  38.     int maxId = -1;
  39.  
  40.    
  41.     for(int i = 0; i < n; i++){
  42.         cin >> a >> b;
  43.         quality[a]++;
  44.         if(quality[a] >= max){
  45.            max = quality[a];
  46.            maxId = a;
  47.            answears[b] = maxId;
  48.        }
  49.     }  
  50.     answears[0] = -1;
  51.    
  52.     cin >> t;
  53.    
  54.     for(int i = 0; i < t; i++){
  55.         cin >> a;
  56.         pair<int, int> find = *(--answears.upper_bound(a));
  57.         cout << find.second << endl;
  58.     }
  59.    
  60.    
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment