/*************************************
* author: marvinthang *
* created: 26.08.2022 17:36:44 *
*************************************/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define div ___div
#define left ___left
#define right ___right
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define MASK(i) (1LL << (i))
#define FULL(i) (MASK(i) - 1)
#define BIT(x, i) ((x) >> (i) & 1)
#define __builtin_popcount __builtin_popcountll
#define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u)
#define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class T> print_op(vector <T>) { out << '{'; for (size_t i = 0; i + 1 < u.size(); ++i) out << u[i] << ", "; if (!u.empty()) out << u.back(); return out << '}'; }
template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; }
template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.fi << ", " << u.se << ')'; }
template <class A, class B> inline bool minimize(A &a, B b) { A eps = 1e-9; if (a > b + eps) { a = b; return true; } return false; }
template <class A, class B> inline bool maximize(A &a, B b) { A eps = 1e-9; if (a + eps < b) { a = b; return true; } return false; }
const double PI = 3.1415926535897932384626433832795; // acos(-1.0); atan(-1.0);
const int dir[] = {1, 0, -1, 0, 1, 1, -1, -1, 1}; // {2, 1, -2, -1, -2, 1, 2, -1, 2};
const long long oo = 1e18;
long long max_weights(int numCol, int numCatfish, vector <int> cols, vector <int> rows, vector <int> weights) {
vector <vector <pair <int, long long>>> atCol(numCol);
for (int i = 0; i < numCatfish; ++i)
atCol[cols[i]].push_back(make_pair(rows[i], weights[i]));
for (int i = 0; i < numCol; ++i) {
atCol[i].push_back(make_pair(numCol, 0));
sort(atCol[i].begin(), atCol[i].end());
long long pref = 0;
for (auto &[_, p]: atCol[i]) {
pref += p;
p = pref;
}
}
auto prefix_sum = [&] (int i, int x) -> long long {
assert(0 <= i && i < numCol);
auto it = lower_bound(atCol[i].begin(), atCol[i].end(), make_pair(x, -1LL));
if (it != atCol[i].begin()) return prev(it)->se;
return 0;
};
vector <vector <vector <long long>>> F(numCol, vector <vector <long long>> (2));
for (int i = 0; i < numCol; ++i) {
F[i][0].assign(atCol[i].size(), 0);
F[i][1].assign(atCol[i].size(), 0);
// cout << atCol[i] << '\n';
if (!i) continue;
// // down
long long ma = 0;
for (int cur = atCol[i].size(), pre = atCol[i - 1].size(); cur--; ) {
while (pre > 0 && atCol[i - 1][pre - 1].fi >= atCol[i][cur].fi)
--pre, maximize(ma, max(F[i - 1][0][pre], F[i - 1][1][pre]) + prefix_sum(i, atCol[i - 1][pre].fi));
maximize(F[i][0][cur], ma - prefix_sum(i, atCol[i][cur].fi));
// cout << i << " 0 " << atCol[i][cur].fi - 1 << ' ' << F[i][0][cur] << '\n';
}
// // up
ma = i > 1 ? max(*max_element(F[i - 2][0].begin(), F[i - 2][0].end()),
*max_element(F[i - 2][1].begin(), F[i - 2][1].end())) : 0;
for (int cur = 0, pre = -1; cur < atCol[i].size(); ++cur) {
while (pre + 1 < atCol[i - 1].size() && atCol[i - 1][pre + 1].fi <= atCol[i][cur].fi)
++pre, maximize(ma, F[i - 1][1][pre] - prefix_sum(i - 1, atCol[i - 1][pre].fi));
maximize(F[i][1][cur], ma + prefix_sum(i - 1, atCol[i][cur].fi));
// cout << i << " 1 " << atCol[i][cur].fi - 1 << ' ' << F[i][1][cur] << '\n';
}
}
return max(*max_element(F[numCol - 1][0].begin(), F[numCol - 1][0].end()),
*max_element(F[numCol - 1][1].begin(), F[numCol - 1][1].end()));
}
// void process(void) {
// int n, m; cin >> n >> m;
// vector <int> x(m), y(m), w(m);
// cin >> x >> y >> w;
// cout << max_weights(n, m, x, y, w) << '\n';
// }
// int main(void) {
// ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
// file("ioi22_day1_fish");
// process();
// cerr << "Time elapsed: " << TIME << " s.\n";
// return (0^0);
// }
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:74:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for (int cur = 0, pre = -1; cur < atCol[i].size(); ++cur) {
| ~~~~^~~~~~~~~~~~~~~~~
fish.cpp:75:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | while (pre + 1 < atCol[i - 1].size() && atCol[i - 1][pre + 1].fi <= atCol[i][cur].fi)
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
23120 KB |
Output is correct |
2 |
Correct |
70 ms |
26072 KB |
Output is correct |
3 |
Correct |
33 ms |
20640 KB |
Output is correct |
4 |
Correct |
32 ms |
20556 KB |
Output is correct |
5 |
Correct |
183 ms |
37020 KB |
Output is correct |
6 |
Correct |
179 ms |
37964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
104 ms |
27464 KB |
Output is correct |
3 |
Correct |
149 ms |
31544 KB |
Output is correct |
4 |
Correct |
64 ms |
22976 KB |
Output is correct |
5 |
Correct |
86 ms |
26016 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
45 ms |
20568 KB |
Output is correct |
11 |
Correct |
32 ms |
20600 KB |
Output is correct |
12 |
Correct |
84 ms |
23080 KB |
Output is correct |
13 |
Correct |
80 ms |
26016 KB |
Output is correct |
14 |
Correct |
85 ms |
23020 KB |
Output is correct |
15 |
Correct |
87 ms |
25596 KB |
Output is correct |
16 |
Correct |
87 ms |
23008 KB |
Output is correct |
17 |
Correct |
68 ms |
25524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
20564 KB |
Output is correct |
2 |
Correct |
31 ms |
20556 KB |
Output is correct |
3 |
Correct |
55 ms |
20676 KB |
Output is correct |
4 |
Correct |
49 ms |
22160 KB |
Output is correct |
5 |
Correct |
78 ms |
25008 KB |
Output is correct |
6 |
Correct |
91 ms |
25484 KB |
Output is correct |
7 |
Correct |
84 ms |
25548 KB |
Output is correct |
8 |
Correct |
81 ms |
25516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
224 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
224 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
26 ms |
3444 KB |
Output is correct |
18 |
Correct |
26 ms |
4012 KB |
Output is correct |
19 |
Correct |
24 ms |
3816 KB |
Output is correct |
20 |
Correct |
25 ms |
3856 KB |
Output is correct |
21 |
Correct |
21 ms |
3752 KB |
Output is correct |
22 |
Correct |
58 ms |
6868 KB |
Output is correct |
23 |
Correct |
7 ms |
928 KB |
Output is correct |
24 |
Correct |
22 ms |
2476 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
224 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
26 ms |
3444 KB |
Output is correct |
18 |
Correct |
26 ms |
4012 KB |
Output is correct |
19 |
Correct |
24 ms |
3816 KB |
Output is correct |
20 |
Correct |
25 ms |
3856 KB |
Output is correct |
21 |
Correct |
21 ms |
3752 KB |
Output is correct |
22 |
Correct |
58 ms |
6868 KB |
Output is correct |
23 |
Correct |
7 ms |
928 KB |
Output is correct |
24 |
Correct |
22 ms |
2476 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
788 KB |
Output is correct |
27 |
Correct |
3 ms |
980 KB |
Output is correct |
28 |
Correct |
114 ms |
14548 KB |
Output is correct |
29 |
Correct |
191 ms |
19944 KB |
Output is correct |
30 |
Correct |
206 ms |
19396 KB |
Output is correct |
31 |
Correct |
178 ms |
19392 KB |
Output is correct |
32 |
Correct |
172 ms |
20964 KB |
Output is correct |
33 |
Correct |
178 ms |
19296 KB |
Output is correct |
34 |
Correct |
207 ms |
19368 KB |
Output is correct |
35 |
Correct |
75 ms |
8572 KB |
Output is correct |
36 |
Correct |
177 ms |
20548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
20564 KB |
Output is correct |
2 |
Correct |
31 ms |
20556 KB |
Output is correct |
3 |
Correct |
55 ms |
20676 KB |
Output is correct |
4 |
Correct |
49 ms |
22160 KB |
Output is correct |
5 |
Correct |
78 ms |
25008 KB |
Output is correct |
6 |
Correct |
91 ms |
25484 KB |
Output is correct |
7 |
Correct |
84 ms |
25548 KB |
Output is correct |
8 |
Correct |
81 ms |
25516 KB |
Output is correct |
9 |
Correct |
104 ms |
25292 KB |
Output is correct |
10 |
Correct |
64 ms |
15908 KB |
Output is correct |
11 |
Correct |
183 ms |
31196 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
35 ms |
20656 KB |
Output is correct |
19 |
Correct |
43 ms |
20636 KB |
Output is correct |
20 |
Correct |
31 ms |
20516 KB |
Output is correct |
21 |
Correct |
34 ms |
20520 KB |
Output is correct |
22 |
Correct |
102 ms |
25496 KB |
Output is correct |
23 |
Correct |
133 ms |
31028 KB |
Output is correct |
24 |
Correct |
165 ms |
31180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
23120 KB |
Output is correct |
2 |
Correct |
70 ms |
26072 KB |
Output is correct |
3 |
Correct |
33 ms |
20640 KB |
Output is correct |
4 |
Correct |
32 ms |
20556 KB |
Output is correct |
5 |
Correct |
183 ms |
37020 KB |
Output is correct |
6 |
Correct |
179 ms |
37964 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
104 ms |
27464 KB |
Output is correct |
9 |
Correct |
149 ms |
31544 KB |
Output is correct |
10 |
Correct |
64 ms |
22976 KB |
Output is correct |
11 |
Correct |
86 ms |
26016 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
45 ms |
20568 KB |
Output is correct |
17 |
Correct |
32 ms |
20600 KB |
Output is correct |
18 |
Correct |
84 ms |
23080 KB |
Output is correct |
19 |
Correct |
80 ms |
26016 KB |
Output is correct |
20 |
Correct |
85 ms |
23020 KB |
Output is correct |
21 |
Correct |
87 ms |
25596 KB |
Output is correct |
22 |
Correct |
87 ms |
23008 KB |
Output is correct |
23 |
Correct |
68 ms |
25524 KB |
Output is correct |
24 |
Correct |
33 ms |
20564 KB |
Output is correct |
25 |
Correct |
31 ms |
20556 KB |
Output is correct |
26 |
Correct |
55 ms |
20676 KB |
Output is correct |
27 |
Correct |
49 ms |
22160 KB |
Output is correct |
28 |
Correct |
78 ms |
25008 KB |
Output is correct |
29 |
Correct |
91 ms |
25484 KB |
Output is correct |
30 |
Correct |
84 ms |
25548 KB |
Output is correct |
31 |
Correct |
81 ms |
25516 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
224 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
26 ms |
3444 KB |
Output is correct |
49 |
Correct |
26 ms |
4012 KB |
Output is correct |
50 |
Correct |
24 ms |
3816 KB |
Output is correct |
51 |
Correct |
25 ms |
3856 KB |
Output is correct |
52 |
Correct |
21 ms |
3752 KB |
Output is correct |
53 |
Correct |
58 ms |
6868 KB |
Output is correct |
54 |
Correct |
7 ms |
928 KB |
Output is correct |
55 |
Correct |
22 ms |
2476 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
6 ms |
788 KB |
Output is correct |
58 |
Correct |
3 ms |
980 KB |
Output is correct |
59 |
Correct |
114 ms |
14548 KB |
Output is correct |
60 |
Correct |
191 ms |
19944 KB |
Output is correct |
61 |
Correct |
206 ms |
19396 KB |
Output is correct |
62 |
Correct |
178 ms |
19392 KB |
Output is correct |
63 |
Correct |
172 ms |
20964 KB |
Output is correct |
64 |
Correct |
178 ms |
19296 KB |
Output is correct |
65 |
Correct |
207 ms |
19368 KB |
Output is correct |
66 |
Correct |
75 ms |
8572 KB |
Output is correct |
67 |
Correct |
177 ms |
20548 KB |
Output is correct |
68 |
Correct |
104 ms |
25292 KB |
Output is correct |
69 |
Correct |
64 ms |
15908 KB |
Output is correct |
70 |
Correct |
183 ms |
31196 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
1 ms |
300 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
296 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
35 ms |
20656 KB |
Output is correct |
78 |
Correct |
43 ms |
20636 KB |
Output is correct |
79 |
Correct |
31 ms |
20516 KB |
Output is correct |
80 |
Correct |
34 ms |
20520 KB |
Output is correct |
81 |
Correct |
102 ms |
25496 KB |
Output is correct |
82 |
Correct |
133 ms |
31028 KB |
Output is correct |
83 |
Correct |
165 ms |
31180 KB |
Output is correct |
84 |
Correct |
228 ms |
36016 KB |
Output is correct |
85 |
Correct |
227 ms |
37848 KB |
Output is correct |
86 |
Correct |
244 ms |
35008 KB |
Output is correct |
87 |
Correct |
238 ms |
37112 KB |
Output is correct |
88 |
Correct |
0 ms |
212 KB |
Output is correct |
89 |
Correct |
245 ms |
37096 KB |
Output is correct |
90 |
Correct |
234 ms |
38084 KB |
Output is correct |
91 |
Correct |
174 ms |
38844 KB |
Output is correct |