fzu2077--violence Skills--the tallest tree

Source: Internet
Author: User

Lzs planted n trees, each tree growing a certain height every day. One day, Lzs want to know how the tree grows, can you find out how high the tallest tree is on that day?

Input

There are several sets of test data, the first row of each group of data input two integers n,m (1<=n,m<=100000), the next n rows, each row two integers, a, B (0<=a,b<=100000), indicating the height of the No. 0 day and the height of the daily growth of the tree. Next m lines, one integer x (0<=x<=100000) per line, indicate how high the tree with the highest number of X days is asked.

Output

For each query output line, the height of the tallest tree of the day.

Sample Input

1 3 10 4 1 2 3

Sample Output

14 18 22
/* First from the big to the small sort according to the V, so that if once the height is reached, as long as the previous several offline to the B according to the Order of the day, each update index, after processing returned the original sequence number */#include <cstdio> #include < Cstring> #include <algorithm>using namespace std;const int MAX = 100000 + 10;struct edge{int h, v;} a[max];struct edge1{int D, h, id;}    B[max];bool CMP (Edge I, Edge j) {if (i.v = = j.v) return i.h > j.h; return i.v > j.v;} BOOL Cmp1 (Edge1 I, Edge1 j) {return I.D < J.D.;} BOOL Cmp2 (Edge1 I, Edge1 j) {return i.id < j.id;}    int main () {int n, m; while (~SCANF ("%d%d", &n, &m)) {for (int i = 1; I <= n; i++) {scanf ("%d%d", &a[i].h, &a        [I].V];        } sort (A + 1, a + n + 1, CMP);            for (int i = 1; I <= m; i++) {scanf ("%d", &AMP;B[I].D);        B[i].id = i;        } sort (b + 1, B + M + 1, CMP1);        int max1 = 0, index = 0;                for (int i = 1; I <= n; i++) {if (a[i].h >= max1) {max1 = a[i].h;            index = i; }} INT Day = index; for (int i = 1, i <= m; i++) {for (int j = 1, J <= Day; j + +) {int temp = B[I].D * A[J].V + A                [J].h;                    if (temp >= max1) {index = j;                Max1 = temp;            }} day = index;        B[i].h = Max1;        } sort (b + 1, B + M + 1, CMP2);        for (int i = 1; I <= m; i++) printf ("%d\n", b[i].h); } return 0;}

  

fzu2077--violence Skills--the tallest tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.