Uvalive 6611 Alice's Print Service two points

Source: Internet
Author: User

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 was printing less than pages are cents per page, but when printing wasn't less than pages, You just need-pay is only cents per page. It's easy-to-figure-out-if-you-want to print-pages, the best choice are to print a extra blank page so that the MO Ney need to pay is 100x10 cents instead of 99x20 cents.
Now given the description of pricing strategy and some queries, your task was to figure out the best ways to complete those Queries in order to save money.

Inputthe first line contains a integer T (≈10) which is the number of test cases. Then T cases follow.
Each case contains 3 lines. The first line contains the 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 was printing no less than Si, and less than SI+1 pages are PI cents per page (for i=1..n-1). The price was printing no less than SN pages are PN cents per page. The third line containing M integers Q1. QM (0≤QI≤109) is the queries.

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

Sample Input12, Output010001000 Source2013 Asia Changsha Regional Contest
/************************************************author:p k28created time:2015/10/15 20:05:30File name:ch angchun1.cpp*************************************************/#include<iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<math.h>#include<stdlib.h>#include<iomanip>#include<list>#include<deque>#include<stack>#defineull unsigned long Long#definell Long Long#defineMoD 90001#defineINF 1e13#defineMAXN 100070#defineCLE (a) memset (A,0,sizeof (a))Constull inf = 1LL << A;Const Doubleeps=1e-5;using namespacestd;BOOLcmpintAintBB) {    returnA>b;}intn,m;ll x[maxn],p[maxn];ll MINN[MAXN];intMain () {#ifndef Online_judge freopen ("In.txt","R", stdin); #endif    //freopen ("OUT.txt", "w", stdout);    intT; CIN>>T;  while(t--) {cin>>n>>m;  for(intI=1; i<=n;i++) {scanf ("%lld%lld",&x[i],&P[i]); } minn[n+1]=INF;  for(inti=n;i>=1; i--) {Minn[i]=min (minn[i+1],p[i]*X[i]);        } ll A,ans;  for(intI=1; i<=m;i++) {scanf ("%lld",&a); intPos=lower_bound (x+1, x+1+N,A)-x; Ans=min (a*p[pos-1],minn[pos]); printf ("%lld\n", ans); }    }    return 0;}

Uvalive 6611 Alice's Print Service two points

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.