I was trying this problem for quite a while, but failed to come up with the correct solution. Maybe you guys can help me.
Problem link: http://main.edu.pl/en/archive/oi/2/sze
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
I was trying this problem for quite a while, but failed to come up with the correct solution. Maybe you guys can help me.
Problem link: http://main.edu.pl/en/archive/oi/2/sze
Название |
---|
Think about some job i, i+1. The total time to complete job i+1 (in order of [1 ... i-1] [i] [i+1]) is
T + aiT + bi + ai + 1(T + aiT + bi) + bi + 1
= (ai + 1 + 1)((ai + 1)T + bi) + bi + 1
when T = total time took to complete till job i-1
now think that we process in order of [1 ... i-1] [i+1] [i], then the total time is
(ai + 1)((ai + 1 + 1)T + bi + 1) + bi
Say ci = ai + 1. now, if this inequality holds, it's better to swap job i and i+1.
ci + 1ciT + ci + 1bi + bi + 1 > cici + 1T + cibi + 1 + bi
which is
ci + 1bi + bi + 1 > cibi + 1 + bi
now replace ci to ai, we get :
ai + 1bi > bi + 1ai
So, if above equality holds, we should swap i and i+1. This is essentially angular sort.
code : http://ideone.com/c70x8s
Thanks a lot. That's a really nice solution :)