zoukankan      html  css  js  c++  java
  • Alice's Print Service

    Alice's Print Service

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her print service found some tricks to save money.

    For example, the price when printing less than 100 pages is 20 cents per page, but when printing not less than 100 pages, you just need to pay only 10 cents per page. It's easy to figure out that if you want to print 99 pages, the best choice is to print an extra blank page so that the money you need to pay is 100 × 10 cents instead of 99 × 20 cents.

    Now given the description of pricing strategy and some queries, your task is to figure out the best ways to complete those queries in order to save money.

    Input

    The first line contains an integer T (≈ 10) which is the number of test cases. Then T cases follow.

    Each case contains 3 lines. The first line contains two integers n, m (0 < n, m ≤ 105). The second line contains 2n integers s1, p1, s2, p2, ..., sn, pn (0=s1 < s2 < ... < sn ≤ 109, 109 ≥ p1 ≥ p2 ≥ ... ≥ pn ≥ 0). The price when printing no less than si but less than si+1 pages is pi cents per page (for i=1..n-1). The price when printing no less than sn pages is pn cents per page. The third line containing m integers q1 .. qm (0 ≤ qi ≤ 109) are the queries.

    Output

    For each query qi, you should output the minimum amount of money (in cents) to pay if you want to print qi pages, one output in one line.

    Sample Input

    1
    2 3
    0 20 100 10
    0 99 100

    Sample Output

    0
    1000
    1000
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 using namespace std;
     6 typedef long long LL;
     7 
     8 LL a[100003],b[100003];
     9 LL f[100003];
    10 
    11 void prepare(LL n)
    12 {
    13     LL Min=b[n]*a[n];
    14     LL ans;
    15     f[n]=Min;
    16     for(LL i=n-1;i>=1;i--)
    17     {
    18         ans=a[i]*b[i];
    19         if(Min>ans)
    20             Min=ans;
    21         f[i]=Min;
    22     }
    23 }
    24 LL EF(LL x,LL l,LL r)
    25 {
    26     LL mid=(l+r)/2;
    27     while(l<r)
    28     {
    29         if(a[mid]>x)
    30             r=mid-1;
    31         else if(a[mid]<x)
    32             l=mid;
    33         else if(a[mid]==x)
    34             return mid;
    35         mid=(l+r+1)/2;
    36     }
    37     return mid;
    38 }
    39 
    40 int main()
    41 {
    42     LL T;
    43     LL i,n,m,x,k;
    44     scanf("%lld",&T);
    45     while(T--)
    46     {
    47         scanf("%lld%lld",&n,&m);
    48         for(i=1;i<=n;i++)
    49         {
    50             scanf("%lld%lld",&a[i],&b[i]);
    51         }
    52         prepare(n);
    53         while(m--)
    54         {
    55             scanf("%lld",&x);
    56             k=EF(x,1,n);
    57             LL ans=x*b[k];
    58             if(k+1<=n && ans>f[k+1]) ans=f[k+1];
    59             printf("%lld
    ",ans);
    60         }
    61     }
    62     return 0;
    63 }
  • 相关阅读:
    drf请求生命周期
    正向代理和反向代理
    cbv源码分析
    Python搭建调用本地dll的Windows服务(浏览器可以访问,附测试dll64位和32位文件)
    Python实现聊天机器人接口封装部署
    Python实现机器人语音聊天
    Python爬虫下载美女图片(不同网站不同方法)
    微信小程序-点餐系统
    Win10系统Python3.8的升级与安装
    Python破解Wifi密码思路
  • 原文地址:https://www.cnblogs.com/tom987690183/p/3440415.html
Copyright © 2011-2022 走看看