Round #240 B. Mashmokh and Tokens(Div.2)

Bimokh is Mashmokh‘s boss. For the following ndays he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can‘t use it in any other day to get more money. If a worker gives back w tokens then he‘ll get  dollars.

Mashmokh likes the tokens however he likes money more. That‘s why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has n numbersx1,?x2,?...,?xn. Number xi is the number of tokens given to each worker on the i-th day. Help him calculate for each of n days the number of tokens he can save.

Input

The first line of input contains three space-separated integers n,?a,?b (1?≤?n?≤?105; 1?≤?a,?b?≤?109). The second line of input contains n space-separated integers x1,?x2,?...,?xn (1?≤?xi?≤?109).

Output

Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day.

Example

Input

5 1 412 6 11 9 1

Output

0 2 3 1 1 

Input

3 1 21 2 3

Output

1 0 1 

Input

1 1 11

Output

0 
 1 /*
 2 题意:老板一天发x张代币券,员工能用它来换大洋,用w张代币券可换[a*w/b](下取整)块大洋,代币券只能当天适用,求换最多大洋时最多能留多少代币券
 3 比如a=3,b=7,x=4时,我最多能换3×4/7=1块大洋,但是我显然用3张代币券就能换1块大洋,所以多的1块就应该被保留
 4 设t为当天最多换得的大洋有t=a*x/b,因为是下取整,有不等式t<=ax/b成立,我们现在只要找一个最小的x使得不等式成立,
 5 为了将变量区分开,设至少用y张代币券换t块大洋,有不等式t<=ay/b成立,化简得y>=bt/a,x-y即所求
 6 注意数据范围a,b,x可达10^9,相乘将达到10^18,所以需要用long long
 7 */
 8
 9 /*
10 #include <iostream>
11 #include <stdio.h>
12 using namespace std;
13 int main(){
14 long long  n,a,b,i,x,temp,t;
15  scanf("%I64d",&n,&a,&b);
16  for(i=0;i<n;i++){
17     scanf("%I64d",&x);
18     t=(x*a)/b;     ///
19     if((t*b)%a==0) temp=(t*b)/a;
20     else temp=(t*b)/a+1;
21     printf("%I64d",x-temp);
22  }
23  printf(" ");
24     return 0;
25 }
26
27 */
28 #include<stdio.h>
29 #include<iostream>
30 using namespace std;
31
32 int main()
33 {
34     long long n,a,b,t,y,l,r,mid;
35     scanf("%I64d%I64d%I64d",&n,&a,&b);
36     long long x,ans;
37     for (int i=0;i<n;i++){
38         scanf("%I64d",&x);
39         t=a*x/b;
40         if ((t*b)%a==0) y=t*b/a;
41         else y=t*b/a + 1;
42         printf("%I64d ",x-y);
43         printf(" ");
44     }
45     return 0;
46 }
				
时间: 2024-10-14 02:36:09

Round #240 B. Mashmokh and Tokens(Div.2)的相关文章

Codeforces Round #240 (Div. 2) (ABCDE题解)

题目链接:http://codeforces.com/contest/415 A. Mashmokh and Lights time limit per test:1 second memory limit per test:256 megabytes Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are index

Codeforces Round #240 (Div. 1)---B.Mashmokh and ACM(dp)

Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tas

Codeforces Round #240 (Div. 1)B---Mashmokh and ACM(水dp)

Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tas

CodeForces - 415B Mashmokh and Tokens

Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens b

【Codeforces Round 1129】[Alex Lopashev Thanks-Round] (Div. 1)

Codeforces Round 1129 这场模拟比赛做了\(A1\).\(A2\).\(B\).\(C\),\(Div.1\)排名40. \(A\)题是道贪心,可以考虑每一个站点是分开来的,把目的地最小编号的留到最后,所以答案稍微算一下就行了. \(B\)题是道找规律,首先可以很容易地发现只要前面弄个负数的开头,错误算法就会忽略掉这一个值,所以利用这个来构造答案.(最讨厌构造题了)然后推导一番式子就会发现如果我们将第一个值放-1,则 \(\sum_{i=2}^na_i=k+n\), 再更改一

Round #336 A. Saitama Destroys Hotel(Div.2)

Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special - it starts on the top floor, can only move down, and has infinite capacity. Fl

Round #428 A. Arya and Bran(Div.2)

Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by

[Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2) ](A~E)

A: 题目大意:给你一个数字串,每个数字只可以用一次,求最多可以组成多少个电话号码(可以相同),电话号码第一个数字为$8$,且长度为$11$ 题解:限制为$8$的个数和总长度,直接求 卡点:无 C++ Code: #include <cstdio> #include <algorithm> #define maxn 1000 inline int min(int a, int b) {return a < b ? a : b;} inline int max(int a, i

Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2)

A.Phone Numbers 题意:给你n个数字,每个数字最多只能用一次,问你最多能组成以8开头的11位电话号码有多少个 思路:模拟即可,注意char数组读入是从0下标开始的(在这里被hack了...) 1 #include<bits/stdc++.h> 2 int main() 3 { 4 int n,num=0,ans=0; 5 char c[105]; 6 scanf("%d%s",&n,c); 7 for(int i=0;i<n;i++)if(c[i