Time limit: 2 seconds
Space limit: 65536K
In order to find a job that he is satisfied with, Niuniu collected the difficulty and pay of each job. The standard for Niuniu to choose a job is to choose the job with the highest pay when the difficulty does not exceed its own ability value. After Niu Niu selected his job, Niu Niu's friends came to Niu Niu to help him choose a job, and Niu Niu still used his own standards to help his friends. Niuniu has too many friends, so he had to give you this task.
Enter description:
Each input contains a test case. The first line of each test case contains two positive integers, representing the number of jobs N (N<=100000) and the number of small partners M (M<=100000). The next N lines each contain two positive integers representing the difficulty Di (Di<=1000000000) and the reward Pi (Pi<=1000000000) of the job, respectively. The next line contains M positive integers, which represent the ability values Ai of the M small partners (Ai<=1000000000). Guaranteed that no two jobs pay the same.
Output description:
For each buddy, output a positive integer on a separate line to represent the highest reward he can get. A job can be selected by multiple people.
Input example 1:
3 3 1 100 10 1000 1000000000 1001 9 10 1000000000
Output example 1:
100 1000
1001
AC Code:::
#include<iostream> #include<vector> #include<map> #include<algorithm> using namespace std; intmain() { int N; int M; cin >> N >> M; map<int, int>mp; vector<int> v; vector<int> v2; for (int i = 0; i < N; ++i) { int di, pi; cin >> di >> pi; v.push_back(di); mp.insert(make_pair(di, pi)); } for (int i = 0; i < M; ++i) { int t; cin >> t; v.push_back(t); v2.push_back(t); if (mp.find(t) == mp.end()) mp[t] = 0; } sort(v.begin(), v.end()); int maxpi = 0; for (auto i : v) { int a = mp[i]; maxpi = max(maxpi, mp[i]); mp[i] = maxpi; } for (int i = 0; i < v2.size(); ++i) { cout << mp[v2[i]] << endl; } return 0; }