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.
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3408 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 135 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
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.
| Name |
|---|



But why do you sort the pi PLUS di array and not a pi minus di array?
because when we have subtracted di for not washing a dish, we need to add di back to make it 0 if we wash the dish and also add the pi value.
I know that we have to readd the pi value in order to nulify the subtraction effect. BUT wouldn't it be more logic to sort pi — di, to find which dish is more efficiently to wash and not have big losses?
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
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.