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

Автор spontaneously, история, 10 лет назад, По-английски

Problem Can anyone help me with this problem I think its a greedy problem but I'm not able to find out a correct approach.

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

»
10 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +23 Проголосовать: не нравится
  • If you don't wash any dish, then your final score will be . Let's call that x.
  • Now, suppose you wash some dishes. Each dish i that you wash will contribute with pi to the answer instead of  - di, so for all the dishes that you wash, you must add pi + di to x.
  • Naturally, we want to take the elements with biggest pi + di, so we sort the dishes in non-increasing order of pi + di and then our answer will be .-
»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In this problem we are affected by a total amount of (p[i]+d[i]) so lets create another variable x =p[i]+d[i] and now sort the structure first with respect to x and if x is equal then with respect to p[i]. This would be an optimal approach because we'll be taking the values that would affect our total payment to a maximum extent. My code :https://ideone.com/dvm2ah

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -9 Проголосовать: не нравится

in the name of allah, most mrcifull

consider this test case:

2 1

1000 9

999 1

if we sort in non-increasing order of pi — di we will chose second one for washing and we will have 9 — 999 money

but if we sort in non-increasing order of pi + di we will chose first one and we will have 1000 — 1 money

i wanna say thank you spontaneously for this blog.