Title Description
In order to find satisfying jobs, beef collect the difficulty and rewards of each job. Standard Taurus selected to work in the case of difficulty does not exceed the value of their own capacity, Taurus choose the highest paying jobs. After their work is selected beef, beef beef little friends came to help work the election, beef still use their own criteria to help small partners. Taurus too much of a small partner, so he had to put this task to you.
Enter a description:
Each input comprises a test.
The first line of each test case contains two positive integers, respectively, the number of working N (N <= 100000) and small partner M (M <= 100000).
The following N lines contains two positive integers, respectively, of the difficulty of the work Di (Di <= 1000000000) and compensation Pi (Pi <= 1000000000).
The next line contains M a positive integer, the ability to represent the value of M small partner Ai (Ai <= 1000000000).
There is no guarantee the two tasks of the same reward.
Output Description:
For each small partner, in a separate line output a positive integer representing the highest reward he can get. A job can be selected more than one person.
Example 1
Export
copy100 1000 1001
AC Code:
. 1 #include <bits / STDC ++ H.> 2 the using namespace STD; . 3 . 4 #define N 100001 + 10 . 5 . 6 struct Job . 7 { . 8 int Difficulty; // difficulty . 9 int the salary; // return 10 } JB [N]; . 11 struct Person 12 is { 13 is int ability; // capacity 14 int I; // numbered 15 int the salary = 0 ;// return 16 } PESN [N]; . 17 18 is BOOL CMP (Job JB1, JB2 Job) // according to the difficulty in ascending order . 19 { 20 is return jb1.difficulty < jb2.difficulty; 21 is } 22 is BOOL CMP1 (PS1 Person, PS2 Person) // the small to large capacity 23 is { 24 return ps1.ability < ps2.ability; 25 } 26 is BOOL CMP2 (Person PS1, PS2 Person) // the numbers in ascending order 27 { 28 return ps1.i < ps2.i; 29 } 30 int main() 31 { 32 int n, m; 33 while (scanf("%d%d", &n, &m) != EOF) 34 { 35 for (int i = 0; i < n; i++) 36 cin >> jb[i].difficulty >> jb[i].salary; 37 sort(jb, jb + n, cmp); 38 for (int i = 0; i < m; i++) 39 { 40 pesn[i].i = i; 41 cin >> pesn[i].ability; 42 } 43 sort(pesn, pesn + m, cmp1); 44 // maxmoney中存放到j的最大值 45 int j = 0; 46 int maxmoney = 0; 47 for (int i = 0; i < m; i++) 48 { 49 while (j < n) 50 { 51 if (jb[j].difficulty > pesn[i].ability) 52 break; 53 maxmoney = max(maxmoney, jb[j].salary); 54 j++; 55 } 56 pesn[i].salary = maxmoney; 57 } 58 sort(pesn, pesn + m, cmp2); 59 for (int i = 0; i < m; i++) 60 cout << pesn[i].salary << endl; 61 } 62 return 0; 63 }