Codechef September long challenge 2021 | Covaxin vs Covishield Solution

 

Codechef September long challenge 2021 | Covaxin vs Covishield Solution

  • -TechTalkBot
  • Post commen

There are two types of vaccines available: Covaxin and Covishield.

A black marketeer has XX coins and wants to buy as many vaccines as possible. Due to the black marketing concerns, government has enforced the following policy:

  • ithith dose of Covaxin costs a+(i1)ba+(i−1)⋅b coins for every i1i≥1.

  • ithith dose of Covishield costs c+(i1)dc+(i−1)⋅d coins for every i1i≥1.

The values of the four parameters a,b,ca,b,c and dd, however isn’t constant and might vary from query to query. In general the value of these four parameters for ithith query will be Ai,Bi,CiAi,Bi,Ci and DiDi respectively. Let ansiansi be the maximum total quantity of vaccines the black marketeer can buy corresponding to the ithith query. For each query, you have to find the value of ansiansi.

You will be given integers A1,B1,C1,D1,P,Q,R,S,TA1,B1,C1,D1,P,Q,R,S,T and MM which will define the queries to be followed.

For i1i≥1 and iI1i≤I−1:

  • Ai+1=(Ai+ansiT)modM+PAi+1=(Ai+ansi⋅T)modM+P
  • Bi+1=(Bi+ansiT)modM+QBi+1=(Bi+ansi⋅T)modM+Q
  • Ci+1=(Ci+ansiT)modM+RCi+1=(Ci+ansi⋅T)modM+R
  • Di+1=(Di+ansiT)modM+SDi+1=(Di+ansi⋅T)modM+S .

Note: Since the output is large, prefer using fast input-output methods.

Input Format

  • First line contains of input contains an integer II denoting the number of queries.
  • Second line of input contains five integers X,A1,B1,C1,D1X,A1,B1,C1,D1.
  • Third line of input contains six integers P,Q,R,S,T,MP,Q,R,S,T,M.

Output Format

For each query output the maximum quantity of vaccines the black marketeer can buy.

Constraints

  • 1I51051≤I≤5⋅105
  • 1X,A1,B1,C1,D110181≤X,A1,B1,C1,D1≤1018
  • 1P,Q,R,S,M10181≤P,Q,R,S,M≤1018
  • 1T1091≤T≤109

Subtasks

Subtask #1 (10 points):

  • 1I1031≤I≤103
  • 1X1091≤X≤109
  • Time limit: 11 sec

Subtask #2 (30 points):

  • 1I1031≤I≤103
  • 1X10151≤X≤1015
  • 109A11018109≤A1≤1018
  • 109B11018109≤B1≤1018
  • 109P1018109≤P≤1018
  • 109Q1018109≤Q≤1018
  • Time limit: 11 sec

Subtask #3 (60 points):

  • Original constraints
  • Time limit: 33 sec

Sample Input 1 

3
20 2 3 4 1
3 7 8 4 11 20

Sample Output 1 

4
1
2

Post a Comment

Previous Post Next Post