ZOJ 3726

太差劲了

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cmath>
 5 #define ll long long
 6 using namespace std;
 7 const int N = 1e5 + 10;
 8 const ll INF = 1e18 + 10;
 9 int s[N];
10 ll p[N], c[N];
11 
12 ll read(){
13     char ch=getchar();ll x=0,f=1;
14     while(ch<'0' || ch>'9')    {if(ch=='-')f=-1;ch=getchar();}
15     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
16     return x*f;
17 }
18 
19 int main(){
20     int T = read();
21     while(T--)
22     {
23         int n = read();
24         int m = read();
25         for(register int i = 1 ; i <= n ; i++){
26             s[i] = read();
27             p[i] = read();
28         }
29         ll tmp = INF;
30         for(int i = n ; i >= 1 ; i--){
31             tmp = min(tmp, s[i] * p[i]);
32             c[i] = tmp;
33         }
34         
35         for(register int i = 1 ; i <= m ; i++){
36             ll x = read();
37             if(x == 0){
38                 printf("0
");
39                 continue;
40             }
41             if(x >= s[n]){
42                 printf("%lld
",x * p[n]);
43                 continue;
44             }
45             ll res = INF;
46             int t = upper_bound(s + 1, s + n + 1, x) - s;
47             res = min(res, x * p[t - 1]);
48             res = min(res, c[t]);
49             printf("%lld
",res);
50         }    
51     }
52     
53     return 0;
54 }
原文地址:https://www.cnblogs.com/ecustlegendn324/p/14052833.html