Problem link: https://acm.timus.ru/problem.aspx?space=1&num=1522
In this problem all you have to do is to come up with clever sorting comparator.
This one is fine:
Explanation/Idea
code
After sorting the answer is just:
code
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3382 |
| 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 | 134 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
[Timus 1522] Help to prove solution.
Problem link: https://acm.timus.ru/problem.aspx?space=1&num=1522
In this problem all you have to do is to come up with clever sorting comparator.
This one is fine:
int sign(int x) { return x < 0 ? -1 : x > 0; }
struct info_t {
int a, b, c, id;
int get() const {
if (a <= c) {
return (a + b);
} else {
return -(b + c);
}
}
bool operator <(const info_t &y) const {
int xg = this->get(), yg = y.get();
if (sgn(xg) != sgn(yg)) {
return sgn(xg) > sgn(yg);
} else {
return xg < yg;
}
}
};
After sorting the answer is just:
int64_t ta = 0, tb = 0, tc = 0;
for (const info_t &toy : toys) {
ta += toy.a;
tb = max(ta, tb) + toy.b;
tc = max(tb, tc) + toy.c;
}
// output tc
| Rev. | Lang. | By | When | Δ | Comment | |
|---|---|---|---|---|---|---|
| en18 |
|
sidereal | 2020-02-18 14:45:31 | 206 | ||
| en17 |
|
sidereal | 2020-02-17 20:55:53 | 0 | (published) | |
| en16 |
|
sidereal | 2020-02-17 20:05:35 | 8 | Tiny change: ' \lt c_i$ would hold, then t' -> ' \lt c_i$ held, then t' | |
| en15 |
|
sidereal | 2020-02-17 19:59:13 | 621 | ||
| en14 |
|
sidereal | 2020-02-17 19:52:49 | 889 | ||
| en13 |
|
sidereal | 2020-02-17 19:34:59 | 247 | ||
| en12 |
|
sidereal | 2020-02-17 19:33:49 | 227 | ||
| en11 |
|
sidereal | 2020-02-17 19:31:25 | 110 | ||
| en10 |
|
sidereal | 2020-02-17 19:29:36 | 17 | ||
| en9 |
|
sidereal | 2020-02-17 19:29:03 | 87 | ||
| en8 |
|
sidereal | 2020-02-17 19:27:28 | 4 | ||
| en7 |
|
sidereal | 2020-02-17 19:27:17 | 2 | Tiny change: 'is fine:\n~~~~~\n\' -> 'is fine:\n\n~~~~~\n\' | |
| en6 |
|
sidereal | 2020-02-17 19:27:09 | 17 | ||
| en5 |
|
sidereal | 2020-02-17 19:26:44 | 2 | Tiny change: 'ne:\n~~~~~struct,202' -> 'ne:\n~~~~~\nstruct,202' | |
| en4 |
|
sidereal | 2020-02-17 19:26:38 | 15 | ||
| en3 |
|
sidereal | 2020-02-17 19:26:25 | 139 | ||
| en2 |
|
sidereal | 2020-02-17 19:25:19 | 506 | ||
| en1 |
|
sidereal | 2020-02-17 19:23:11 | 185 | Initial revision (saved to drafts) |
| Name |
|---|


