F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Linear Functions

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 59    Accepted Submission(s): 19


Problem Description
You are given an array with N non-negative integers. Initially, i.e. at time 0, the i-th value of the array is Ai. After t (t is a non-negative integer) time units, it will be increased by t*Bi.
You are also given N integers Pi, and the beauty of the array is simply defined as A1 mod P1 + A2 mod P2 + бн + AN mod PN. The goal is to maximize the beauty of the array. You have T time units.
Your task is to calculate the maximum beauty of the array in T time units and when you can get the maximum beauty. More formally, you have to find the maximum value of (A1+t*B1) mod P1 + (A2+t*B2) mod P2 + бн + (AN + t*BN) mod PN, where t is a non-negative integer in [0, T], and also t which gives maximum value.
 

Input
There are multiple test cases. Please process till EOF (end of file).
The 1st line of each test case contains 2 integers N and T. In the 2nd line, there are N space-separated integers A1, A2, бн , AN. The next line also contains N space-separated integers B1, B2, бн , BN. Then the last line of each test case contains N space-separated integers P1, P2, бн , PN.
1<=N, T<=100000.
For all i (1 <= i <= N), 0 <= Ai, Bi < Pi, 5*10^8 < Pi < 10^9.
For simplicity, all Pi are prime.
All Ai, Bi are randomly and uniformly generated between [0, Pi).
The sum of all N will not exceed 1000000.
The number of test cases is smaller than 250. Most test cases are small.
In at least 50% of cases, N will not exceed 100, at least 80% of cases, N will not exceed 1000.
 

Output
For each test case, you have to print exactly 2 integers in one line, the maximum beauty and the time t in [0, T], which gives the maximum beauty. If there are multiple optimal t values then print the smallest one.
 

Sample Input
5 1 0 0 0 0 0 1 2 3 4 5 2 3 5 7 11
 

Sample Output
15 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 10:35:02, Gzip enabled