Блог пользователя Sai_D_Coder

Автор Sai_D_Coder, 2 года назад, По-английски

Hi guys, I'm solving this problem and this is my code/submission. I'm getting WA for the test case 6. The test case is running fine on both my local computer and as well as Codeforces java Compiler but I'm getting WA when I submit the solution. Can someone help me why is this happening.

Test Case:

Thanks in advance

Полный текст и комментарии »

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

Автор Sai_D_Coder, история, 3 года назад, По-английски

Till the date I have written so many exams for placement this list includes companies like Amazon, American Express, Amdocs etc.., But the thing in every exam i have written i was able to understand the question and was able to implement the idea solving the problem is secondary though... But today morning i have written an exam the question goes like this:

Problem:

An array A of buying points (tuples of days and share prices of a company) and another array B of selling points (tuples of days and share prices of the same company) are given. A trade is defined as buying on some day di at price pi (where (di, pi) are in A) and selling at some day Di at price Pi (where (Di, Pi) are in B). The profit that you make for a trade is defined as the price difference multiplied by the number of days held, which is: (Di – di) * (Pi – pi) You have to maximize the profit using at most one trade. Print the maximum profit that can be made.

Note You can only sell after you have brought the share, i.e., di < Di. The arrays are generated in such a way that A[i][1] = 1000 sqrt(A[i][0]).

Function Description In the provided code snippet, implement the provided getMaxProfit () method using the variables to print the maximum profit that can be made by buying from a set of options in A and selling from a set of options in B. You can write your code in the space below the phrase "Write Code Here". There will be multiple test cases running so the Input and Output should match exactly as provided.

Input Format The first line contains an integer N denoting the size of the array A. The second line contains M denoting the size of the array B. The third line contains the state (the seed to generate input data).

Sample Input 4 --> Denotes size of buying points N. 4 --> Denotes size of selling points M. 653307 --> Denotes state.

Constraints 1 <= N,M <= 100000 1 <= state <= 1000000

Output Format The output should contain an integer denoting the maximum profit that can be made.

Sample Output 2538828

Explanation The generated arrays A and B: A: [(576, 976) (529, 977) (676, 974) (64, 992)] B: [(138, 8893) (391, 8756) (248, 3214) (126, 5022)] The maximum profit can be achieved by buying at day 64, price 992, and selling at day 391, at price 8756. The profit (8756-992) *1391 -64) = 2538828

I can not able to even think a single approach for this even after the exam i worked on this like 2hrs and could not able to understand the Sample Test case. What could be rating of this rating type of Question if such type of question is given in codeforces contest i never solved a problem rating higher than 1300 on codeforces so I'm just Curious and finally I need solution and atleast the explanation of Sample Test Case

Полный текст и комментарии »

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится