Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
Vasya, like movie others, likes to fig in a variety of sweepstakes and lotteries. now he collects wrappings from a famous chocolate bar "Jupiter ". according to the sweepstake rules, each wrapping has an integer written on it-the number of points that
The participating ipant adds to his score as he buys the bar. after a participating ipant earns a certain number of points, he can come to the prize distribution center and exchange the points for prizes. when somebody takes a prize, the prize's cost is simply subtracted
From the number of his points.
Vasya didn't only bought the bars, he also kept a record of how many points each wrapping cost. also, he remembers that he always stucks to the greedy strategy-as soon as he cocould take at least one prize, he went to the prize distribution center and exchanged
The points for prizes. moreover, if he cocould choose between multiple prizes, he chose the most expensive one. if after an exchange Vasya had enough points left to get at least one more prize, then he continued to exchange points.
The sweepstake has the following prizes (the prizes are sorted by increasing of their cost ):
- A mug (costsAPoints ),
-
- A towel (costsBPoints ),
-
- A bag (costsCPoints ),
- A bicycle (costsDPoints ),
-
- A car (costsEPoints ).
Now Vasya wants to recollect what prizes he has stored Ed. You know SequenceP1, Bytes,P2, Please..., please ,...,PN ,
Where PI Is
The number of points Vasya got for I -Th bar. The sequence of points is given in the chronological order. You also know numbers A , B , C , D ,E .
Your task is to find, how many prizes Vasya has Ed, what prizes they are and how many points he's got left after all operations are completed.
Input
The first line contains a single integer N ( 1 bytes ≤ bytesNLimit ≤ limit 50 )
-The number of chocolate bar wrappings that brought points to Vasya. The second line contains space-separated IntegersP1, Bytes,P2, Please..., please ,...,PN (1 bytes ≤ bytesPILimit ≤ limit 109 ).
The third line contains 5 Integers A , B , C ,D , E ( 1 bytes ≤ bytesALatency <latencyBLatency <latencyCLatency <latencyDLatency <latencyELimit ≤ limit 109 )
-The prizes 'costs.
Output
print on the first line 5 integers, separated by a space-the number of mugs, towels, bags, bicycles and cars that Vasya has got, respectively. on the second line print a single integer-the number of points Vasya will have left after all operations of exchange
are completed.
Please, do not use% LLDSpecifier to read or write 64-bit integers in bytes ++. It is preferred to useCIN,CoutStreams
Or% I64dSpecifier.
Sample test (s) Input
33 10 42 4 10 15 20
Output
1 1 1 0 0 1
Input
410 4 39 23 5 10 11 12
Output
3 0 1 0 3 0
Note
In the first sample Vasya gets3Points after eating the first chocolate bar. Then he exchanges2Points
And gets a mug. Vasya winsBagAfter eating the second chocolate bar. Then he winsTowelAfter eating the third chocolate bar.
After all chocolate bars3 bytes-interval 2 bytes + interval 10 bytes-interval 10 bytes + interval 4 bytes-interval 4 bytes = interval 1Points remains.
Solution Description: The question refers to the use of scores for prizes and violence. After each score, you can find whether the score can be exchanged. You can use a double loop.
# Include <iostream> # include <map> # include <string> # include <algorithm> # include <cstdio> # include <cmath> using namespace STD; int N, I, j; long a [5], B [5], po [51], ans; int main () {CIN> N; for (I = 0; I <n; I ++) {CIN> po [I] ;}for (I = 0; I <5; I ++) {CIN> A [I] ;}for (I = 0; I <n; I ++) {ans + = po [I]; for (j = 4; j> = 0; j --) {B [J] + = ANS/A [J]; ans % = A [J] ;}} for (I = 0; I <4; I ++) {cout <B [I] <"" ;}cout <B [4] <Endl; cout <ans <Endl; return 0 ;}