Xtuoj 15503-c

Source: Internet
Author: User

15503-c

Accepted:6 submissions:27 time limit:3000 ms Memory limit:1048576 KB

After solving the little girl's puzzle, the little girl was generous to tell Deemo her name: Alice.
From then on Deemo no longer alone. They live happily together every day. Deemo usually like to play the piano, Alice will sit quietly beside him, see Deemo before read the book.

"Deemo, the puzzles in your book are so hard. Alice looked at the book with a crooked head and a frown.
"If you want to know the answer you can ask me, I have solved it." "The Deemo of the piano was cheerful.
"Really?" A book of this thickness? , do you know the answer to the question? ”
"Well, because before you came, I was a man. ”

Puzzle:
n the individual is playing a game about candles. These people are numbered,..., N. First, the first person has an AI root candle on the hand.
This game carries the M-wheel. In each round, the person with the lowest candle can get the X candle. If more than two people have the fewest candles, the person with the lowest number gets the candle.
The number 1 is their boss. So he can get the Y-candle from other ways before the game starts. Now he wants to know how many candles he can have after the M-wheel.

Input
An integer t that represents the number of samples ($t \leq 10$). The first line of each set of samples has four integers $n, m,x,y (1\leq n,m\leq 200000,1\leq x,y\leq 10^9) $. The second line has n integers $a _1,a_2,..., a_n (1\leq a_i\leq 10^9) $.

Output
Each set of samples an integer represents the maximum number of candles.


Input
1
2 1 2 2
1 2


Output
4

Source

XTU Onlinejudge

Problem solving: Assuming that $a_0$ is not put in, we can use X and y to make a[0] equal to the current value of the remaining number, so that can be

1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =200010;4typedefLong LongLL;5typedef PAIR&LT;LL,int>PLI;6Priority_queue<pli,vector<pli >,greater<pli > >p,q;7 intcnt[maxn],n,m,x,y;8 LL A[MAXN];9LL Solve (intST,LL ret =0) {Ten      while(!q.empty ()) Q.pop (); One      while(!p.empty ()) P.pop (); Amemset (CNT,0,sizeofCNT); -      for(inti =1; I < n; ++i) { - Q.push (PLI (a[i],i)); the P.push (PLI (a[i],i)); -     } -P.push (PLI (a[0] + St,0)); -RET = a[0]; +      for(inti =0; I < m; ++i) { -PLI now =q.top (); + Q.pop (); A         if(Now.first >= a[0]){ atLL k = Ceil (Double(now.first-a[0]-y)/x); -             if(i + MAX (K,0LL) +1<= m && a[0] + k*x <=Now.first) -ret = max (Ret,now.first +x); -         } -Now.first + =x; - Q.push (now); in     } -ret = max (ret,a[0] +St); to      for(inti =0; I < m; ++i) { +PLI now =p.top (); -Now.first + =x; the P.pop (); *         if(Now.second = =0) ret =Max (ret,now.first); $ P.push (now);Panax Notoginseng     } -     returnret; the } + intMain () { A     intKase; thescanf"%d",&Kase); +      while(kase--) { -scanf"%d%d%d%d",&n,&m,&x,&y); $          for(inti =0; I < n; ++i) scanf ("%i64d", A +i); $         if(n = =1) { -printf"%i64d\n", LL (m) *x + (a[0] +y)); -             Continue; the         } -printf"%i64d\n", Solve (y));Wuyi     } the     return 0; - } Wu /* - 1 About 5 4 8 4 $ 1 5 5) 7 8 - */
View Code

Xtuoj 15503-c

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.