Alice ' s Print Service
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1855 Accepted Submission (s): 454
Problem Descriptionalice 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 30 20 100 100 99 100
Sample Output010001000
Source2013 Asia Changsha Regional Contest
"Test Instructions":
Give a printed segment function to print the number of each query, at least how much it costs
"Problem-solving ideas":
If pi <= x < pi+1, the minimum cost is min{pi*x, with the plan after I spend the least money};
In reverse order to record the min[i], for the scheme after I (more print some) the minimum cost of money;;
WA once, Longlong forgot to assign the INF as 0x3f3f3f3f3f3f3f3f~
Recently do water problems are not too careful, and reflect on
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <vector>6#include <map>7#include <queue>8#include <algorithm>9 #defineLL Long LongTen #defineMAXN 110000 One #defineINF 0x3f3f3f3f3f3f3f3f A #defineIn Freopen ("In.txt", "R", stdin); - using namespacestd; - the LL P[MAXN],S[MAXN]; - LL TOL[MAXN]; - - intMainintargcChar Const*argv[]) + { - //in ; + A intT;SCANF ("%d",&t); at while(t--) - { - intn,m; -scanf"%d%d",&n,&m); - - for(intI=0; i<n;i++){ inscanf"%lld%lld",&s[i],&p[i]); -Tol[i] = s[i] *P[i]; to } + - LL MIN[MAXN]; theFill (min,min+maxn,inf); * for(inti=n-1; i>=0; i--){ $Min[i]=min (tol[i],min[i+1]);Panax Notoginseng } - the while(m--) + { ALL x;scanf ("%lld",&x); theLL ans =inf; + inti = Lower_bound (s,s+n,x)-s; - if(s[i]==x) ans = min (p[i]*s[i],min[i]); $ Elseans = min (min[i],p[i-1]*x); $ -printf"%lld\n", ans); - } the } - Wuyi return 0; the}
HDU 4791 Alice's Print Service (2013 Changsha Live race, two minutes)