#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
const ll inf = 1e18;
ll n, a[200005], b[200005], c[200005], sum[200005];
pair<ll,ll> dt[200005], ans;
vector<ll> ord;
vector<pair<ll,ll> > stk;
struct segtree {
pair<ll,ll> val[888888];
ll lazy[888888];
void init (ll SS, ll SE, ll P) {
if(SS == SE) {val[P] = {0, SS}; return;}
ll mid = (SS+SE)/2;
init(SS, mid, 2*P);
init(mid+1, SE, 2*P+1);
val[P] = max(val[2*P], val[2*P+1]);
}
void init () {init(1, n, 1);}
void lazydown (ll P) {
val[2*P].X += lazy[P];
lazy[2*P] += lazy[P];
val[2*P+1].X += lazy[P];
lazy[2*P+1] += lazy[P];
lazy[P] = 0;
}
void update (ll S, ll E, ll SS, ll SE, ll P, ll V) {
if(S <= SS && SE <= E) {
val[P].X += V; lazy[P] += V;
return;
}
if(SE < S || E < SS) return;
lazydown(P);
ll mid = (SS+SE)/2;
update(S, E, SS, mid, 2*P, V);
update(S, E, mid+1, SE, 2*P+1, V);
val[P] = max(val[2*P], val[2*P+1]);
}
void update (ll S, ll E, ll V) {update(S, E, 1, n, 1, V);}
pair<ll,ll> query (ll S, ll E, ll SS, ll SE, ll P) {
if(S <= SS && SE <= E) return val[P];
if(SE < S || E < SS) return {-inf, -inf};
lazydown(P);
ll mid = (SS+SE)/2;
return max(query(S, E, SS, mid, 2*P),
query(S, E, mid+1, SE, 2*P+1));
}
pair<ll,ll> query (ll S, ll E) {return query(S, E, 1, n, 1);}
} seg;
int main()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++) {
scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
sum[i] = sum[i-1] + b[i];
}
seg.init();
stk.push_back({inf, 0});
dt[1] = {a[1], 0};
seg.update(1, 1, dt[1].X);
for(int i=2;i<=n;i++) {
pair<ll,ll> tmp = max(seg.query(1, i-2), {sum[i-1], 0});
dt[i] = {tmp.X + a[i], tmp.Y};
ll cur = c[i] - b[i], prv = 0;
seg.update(1, i-1, b[i]);
while(true) {
if(stk.back().X <= cur) {
seg.update(stk.back().Y+1, i-1, stk.back().X - prv);
prv = stk.back().X;
stk.pop_back();
}
else {
seg.update(stk.back().Y+1, i-1, cur - prv);
stk.push_back({cur, i-1});
break;
}
}
seg.update(i, i, dt[i].X);
}
for(int i=1;i<=n;i++) {
ans = max(ans, {dt[i].X + sum[n] - sum[i], i});
}
printf("%lld\n",ans.X);
for(int i=ans.Y;i;i=dt[i].Y) ord.push_back(i);
int i;
for(i=ans.Y;dt[i].Y;i=dt[i].Y) {
pair<ll, ll> tmp = {-inf, -inf};
for(int j=dt[i].Y+1;j<i;j++) {
tmp = max(tmp, {c[j] - b[j], j});
}
for(int j=dt[i].Y+1;j<tmp.Y;j++) ord.push_back(j);
for(int j=i-1;j>=tmp.Y;j--) ord.push_back(j);
}
while(--i) ord.push_back(i);
for(int i=ans.Y+1;i<=n;i++) ord.push_back(i);
for(int i=0;i<n;i++) printf("%lld ",ord[i]);
}
Compilation message
space.cpp: In function 'int main()':
space.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&n);
~~~~~^~~~~~~~~~~
space.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14328 KB |
Output is correct |
2 |
Correct |
15 ms |
14484 KB |
Output is correct |
3 |
Correct |
15 ms |
14484 KB |
Output is correct |
4 |
Correct |
14 ms |
14484 KB |
Output is correct |
5 |
Correct |
14 ms |
14484 KB |
Output is correct |
6 |
Correct |
15 ms |
14520 KB |
Output is correct |
7 |
Correct |
14 ms |
14756 KB |
Output is correct |
8 |
Correct |
13 ms |
14756 KB |
Output is correct |
9 |
Correct |
14 ms |
14824 KB |
Output is correct |
10 |
Correct |
14 ms |
14824 KB |
Output is correct |
11 |
Correct |
13 ms |
14824 KB |
Output is correct |
12 |
Correct |
14 ms |
14824 KB |
Output is correct |
13 |
Correct |
14 ms |
14824 KB |
Output is correct |
14 |
Correct |
14 ms |
14824 KB |
Output is correct |
15 |
Correct |
15 ms |
14824 KB |
Output is correct |
16 |
Correct |
16 ms |
14824 KB |
Output is correct |
17 |
Correct |
14 ms |
14824 KB |
Output is correct |
18 |
Correct |
15 ms |
14824 KB |
Output is correct |
19 |
Correct |
14 ms |
14824 KB |
Output is correct |
20 |
Correct |
17 ms |
14824 KB |
Output is correct |
21 |
Correct |
14 ms |
14824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14328 KB |
Output is correct |
2 |
Correct |
15 ms |
14484 KB |
Output is correct |
3 |
Correct |
15 ms |
14484 KB |
Output is correct |
4 |
Correct |
14 ms |
14484 KB |
Output is correct |
5 |
Correct |
14 ms |
14484 KB |
Output is correct |
6 |
Correct |
15 ms |
14520 KB |
Output is correct |
7 |
Correct |
14 ms |
14756 KB |
Output is correct |
8 |
Correct |
13 ms |
14756 KB |
Output is correct |
9 |
Correct |
14 ms |
14824 KB |
Output is correct |
10 |
Correct |
14 ms |
14824 KB |
Output is correct |
11 |
Correct |
13 ms |
14824 KB |
Output is correct |
12 |
Correct |
14 ms |
14824 KB |
Output is correct |
13 |
Correct |
14 ms |
14824 KB |
Output is correct |
14 |
Correct |
14 ms |
14824 KB |
Output is correct |
15 |
Correct |
15 ms |
14824 KB |
Output is correct |
16 |
Correct |
16 ms |
14824 KB |
Output is correct |
17 |
Correct |
14 ms |
14824 KB |
Output is correct |
18 |
Correct |
15 ms |
14824 KB |
Output is correct |
19 |
Correct |
14 ms |
14824 KB |
Output is correct |
20 |
Correct |
17 ms |
14824 KB |
Output is correct |
21 |
Correct |
14 ms |
14824 KB |
Output is correct |
22 |
Correct |
14 ms |
14824 KB |
Output is correct |
23 |
Correct |
15 ms |
14824 KB |
Output is correct |
24 |
Correct |
15 ms |
14824 KB |
Output is correct |
25 |
Correct |
14 ms |
14824 KB |
Output is correct |
26 |
Correct |
12 ms |
14920 KB |
Output is correct |
27 |
Correct |
15 ms |
14920 KB |
Output is correct |
28 |
Correct |
14 ms |
14964 KB |
Output is correct |
29 |
Correct |
15 ms |
14968 KB |
Output is correct |
30 |
Correct |
16 ms |
14968 KB |
Output is correct |
31 |
Correct |
13 ms |
14976 KB |
Output is correct |
32 |
Correct |
13 ms |
14976 KB |
Output is correct |
33 |
Correct |
12 ms |
14984 KB |
Output is correct |
34 |
Correct |
14 ms |
14988 KB |
Output is correct |
35 |
Correct |
13 ms |
14992 KB |
Output is correct |
36 |
Correct |
14 ms |
14992 KB |
Output is correct |
37 |
Correct |
13 ms |
14992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14328 KB |
Output is correct |
2 |
Correct |
15 ms |
14484 KB |
Output is correct |
3 |
Correct |
15 ms |
14484 KB |
Output is correct |
4 |
Correct |
14 ms |
14484 KB |
Output is correct |
5 |
Correct |
14 ms |
14484 KB |
Output is correct |
6 |
Correct |
15 ms |
14520 KB |
Output is correct |
7 |
Correct |
14 ms |
14756 KB |
Output is correct |
8 |
Correct |
13 ms |
14756 KB |
Output is correct |
9 |
Correct |
14 ms |
14824 KB |
Output is correct |
10 |
Correct |
14 ms |
14824 KB |
Output is correct |
11 |
Correct |
13 ms |
14824 KB |
Output is correct |
12 |
Correct |
14 ms |
14824 KB |
Output is correct |
13 |
Correct |
14 ms |
14824 KB |
Output is correct |
14 |
Correct |
14 ms |
14824 KB |
Output is correct |
15 |
Correct |
15 ms |
14824 KB |
Output is correct |
16 |
Correct |
16 ms |
14824 KB |
Output is correct |
17 |
Correct |
14 ms |
14824 KB |
Output is correct |
18 |
Correct |
15 ms |
14824 KB |
Output is correct |
19 |
Correct |
14 ms |
14824 KB |
Output is correct |
20 |
Correct |
17 ms |
14824 KB |
Output is correct |
21 |
Correct |
14 ms |
14824 KB |
Output is correct |
22 |
Correct |
14 ms |
14824 KB |
Output is correct |
23 |
Correct |
15 ms |
14824 KB |
Output is correct |
24 |
Correct |
15 ms |
14824 KB |
Output is correct |
25 |
Correct |
14 ms |
14824 KB |
Output is correct |
26 |
Correct |
12 ms |
14920 KB |
Output is correct |
27 |
Correct |
15 ms |
14920 KB |
Output is correct |
28 |
Correct |
14 ms |
14964 KB |
Output is correct |
29 |
Correct |
15 ms |
14968 KB |
Output is correct |
30 |
Correct |
16 ms |
14968 KB |
Output is correct |
31 |
Correct |
13 ms |
14976 KB |
Output is correct |
32 |
Correct |
13 ms |
14976 KB |
Output is correct |
33 |
Correct |
12 ms |
14984 KB |
Output is correct |
34 |
Correct |
14 ms |
14988 KB |
Output is correct |
35 |
Correct |
13 ms |
14992 KB |
Output is correct |
36 |
Correct |
14 ms |
14992 KB |
Output is correct |
37 |
Correct |
13 ms |
14992 KB |
Output is correct |
38 |
Correct |
13 ms |
15264 KB |
Output is correct |
39 |
Correct |
14 ms |
15268 KB |
Output is correct |
40 |
Correct |
14 ms |
15280 KB |
Output is correct |
41 |
Correct |
16 ms |
15280 KB |
Output is correct |
42 |
Correct |
13 ms |
15280 KB |
Output is correct |
43 |
Correct |
13 ms |
15280 KB |
Output is correct |
44 |
Correct |
14 ms |
15280 KB |
Output is correct |
45 |
Correct |
16 ms |
15280 KB |
Output is correct |
46 |
Correct |
15 ms |
15280 KB |
Output is correct |
47 |
Correct |
13 ms |
15280 KB |
Output is correct |
48 |
Correct |
13 ms |
15308 KB |
Output is correct |
49 |
Correct |
15 ms |
15316 KB |
Output is correct |
50 |
Correct |
15 ms |
15456 KB |
Output is correct |
51 |
Correct |
13 ms |
15468 KB |
Output is correct |
52 |
Correct |
13 ms |
15468 KB |
Output is correct |
53 |
Correct |
14 ms |
15468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14328 KB |
Output is correct |
2 |
Correct |
15 ms |
14484 KB |
Output is correct |
3 |
Correct |
15 ms |
14484 KB |
Output is correct |
4 |
Correct |
14 ms |
14484 KB |
Output is correct |
5 |
Correct |
14 ms |
14484 KB |
Output is correct |
6 |
Correct |
15 ms |
14520 KB |
Output is correct |
7 |
Correct |
14 ms |
14756 KB |
Output is correct |
8 |
Correct |
13 ms |
14756 KB |
Output is correct |
9 |
Correct |
14 ms |
14824 KB |
Output is correct |
10 |
Correct |
14 ms |
14824 KB |
Output is correct |
11 |
Correct |
13 ms |
14824 KB |
Output is correct |
12 |
Correct |
14 ms |
14824 KB |
Output is correct |
13 |
Correct |
14 ms |
14824 KB |
Output is correct |
14 |
Correct |
14 ms |
14824 KB |
Output is correct |
15 |
Correct |
15 ms |
14824 KB |
Output is correct |
16 |
Correct |
16 ms |
14824 KB |
Output is correct |
17 |
Correct |
14 ms |
14824 KB |
Output is correct |
18 |
Correct |
15 ms |
14824 KB |
Output is correct |
19 |
Correct |
14 ms |
14824 KB |
Output is correct |
20 |
Correct |
17 ms |
14824 KB |
Output is correct |
21 |
Correct |
14 ms |
14824 KB |
Output is correct |
22 |
Correct |
14 ms |
14824 KB |
Output is correct |
23 |
Correct |
15 ms |
14824 KB |
Output is correct |
24 |
Correct |
15 ms |
14824 KB |
Output is correct |
25 |
Correct |
14 ms |
14824 KB |
Output is correct |
26 |
Correct |
12 ms |
14920 KB |
Output is correct |
27 |
Correct |
15 ms |
14920 KB |
Output is correct |
28 |
Correct |
14 ms |
14964 KB |
Output is correct |
29 |
Correct |
15 ms |
14968 KB |
Output is correct |
30 |
Correct |
16 ms |
14968 KB |
Output is correct |
31 |
Correct |
13 ms |
14976 KB |
Output is correct |
32 |
Correct |
13 ms |
14976 KB |
Output is correct |
33 |
Correct |
12 ms |
14984 KB |
Output is correct |
34 |
Correct |
14 ms |
14988 KB |
Output is correct |
35 |
Correct |
13 ms |
14992 KB |
Output is correct |
36 |
Correct |
14 ms |
14992 KB |
Output is correct |
37 |
Correct |
13 ms |
14992 KB |
Output is correct |
38 |
Correct |
13 ms |
15264 KB |
Output is correct |
39 |
Correct |
14 ms |
15268 KB |
Output is correct |
40 |
Correct |
14 ms |
15280 KB |
Output is correct |
41 |
Correct |
16 ms |
15280 KB |
Output is correct |
42 |
Correct |
13 ms |
15280 KB |
Output is correct |
43 |
Correct |
13 ms |
15280 KB |
Output is correct |
44 |
Correct |
14 ms |
15280 KB |
Output is correct |
45 |
Correct |
16 ms |
15280 KB |
Output is correct |
46 |
Correct |
15 ms |
15280 KB |
Output is correct |
47 |
Correct |
13 ms |
15280 KB |
Output is correct |
48 |
Correct |
13 ms |
15308 KB |
Output is correct |
49 |
Correct |
15 ms |
15316 KB |
Output is correct |
50 |
Correct |
15 ms |
15456 KB |
Output is correct |
51 |
Correct |
13 ms |
15468 KB |
Output is correct |
52 |
Correct |
13 ms |
15468 KB |
Output is correct |
53 |
Correct |
14 ms |
15468 KB |
Output is correct |
54 |
Correct |
13 ms |
15468 KB |
Output is correct |
55 |
Correct |
34 ms |
16540 KB |
Output is correct |
56 |
Correct |
44 ms |
16832 KB |
Output is correct |
57 |
Correct |
37 ms |
17124 KB |
Output is correct |
58 |
Correct |
34 ms |
17416 KB |
Output is correct |
59 |
Correct |
51 ms |
17716 KB |
Output is correct |
60 |
Correct |
37 ms |
18016 KB |
Output is correct |
61 |
Correct |
37 ms |
18440 KB |
Output is correct |
62 |
Correct |
26 ms |
18440 KB |
Output is correct |
63 |
Correct |
18 ms |
18440 KB |
Output is correct |
64 |
Correct |
34 ms |
19068 KB |
Output is correct |
65 |
Correct |
33 ms |
19068 KB |
Output is correct |
66 |
Correct |
32 ms |
19316 KB |
Output is correct |
67 |
Correct |
22 ms |
19316 KB |
Output is correct |
68 |
Correct |
22 ms |
19316 KB |
Output is correct |
69 |
Correct |
36 ms |
19968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
14328 KB |
Output is correct |
2 |
Correct |
15 ms |
14484 KB |
Output is correct |
3 |
Correct |
15 ms |
14484 KB |
Output is correct |
4 |
Correct |
14 ms |
14484 KB |
Output is correct |
5 |
Correct |
14 ms |
14484 KB |
Output is correct |
6 |
Correct |
15 ms |
14520 KB |
Output is correct |
7 |
Correct |
14 ms |
14756 KB |
Output is correct |
8 |
Correct |
13 ms |
14756 KB |
Output is correct |
9 |
Correct |
14 ms |
14824 KB |
Output is correct |
10 |
Correct |
14 ms |
14824 KB |
Output is correct |
11 |
Correct |
13 ms |
14824 KB |
Output is correct |
12 |
Correct |
14 ms |
14824 KB |
Output is correct |
13 |
Correct |
14 ms |
14824 KB |
Output is correct |
14 |
Correct |
14 ms |
14824 KB |
Output is correct |
15 |
Correct |
15 ms |
14824 KB |
Output is correct |
16 |
Correct |
16 ms |
14824 KB |
Output is correct |
17 |
Correct |
14 ms |
14824 KB |
Output is correct |
18 |
Correct |
15 ms |
14824 KB |
Output is correct |
19 |
Correct |
14 ms |
14824 KB |
Output is correct |
20 |
Correct |
17 ms |
14824 KB |
Output is correct |
21 |
Correct |
14 ms |
14824 KB |
Output is correct |
22 |
Correct |
14 ms |
14824 KB |
Output is correct |
23 |
Correct |
15 ms |
14824 KB |
Output is correct |
24 |
Correct |
15 ms |
14824 KB |
Output is correct |
25 |
Correct |
14 ms |
14824 KB |
Output is correct |
26 |
Correct |
12 ms |
14920 KB |
Output is correct |
27 |
Correct |
15 ms |
14920 KB |
Output is correct |
28 |
Correct |
14 ms |
14964 KB |
Output is correct |
29 |
Correct |
15 ms |
14968 KB |
Output is correct |
30 |
Correct |
16 ms |
14968 KB |
Output is correct |
31 |
Correct |
13 ms |
14976 KB |
Output is correct |
32 |
Correct |
13 ms |
14976 KB |
Output is correct |
33 |
Correct |
12 ms |
14984 KB |
Output is correct |
34 |
Correct |
14 ms |
14988 KB |
Output is correct |
35 |
Correct |
13 ms |
14992 KB |
Output is correct |
36 |
Correct |
14 ms |
14992 KB |
Output is correct |
37 |
Correct |
13 ms |
14992 KB |
Output is correct |
38 |
Correct |
13 ms |
15264 KB |
Output is correct |
39 |
Correct |
14 ms |
15268 KB |
Output is correct |
40 |
Correct |
14 ms |
15280 KB |
Output is correct |
41 |
Correct |
16 ms |
15280 KB |
Output is correct |
42 |
Correct |
13 ms |
15280 KB |
Output is correct |
43 |
Correct |
13 ms |
15280 KB |
Output is correct |
44 |
Correct |
14 ms |
15280 KB |
Output is correct |
45 |
Correct |
16 ms |
15280 KB |
Output is correct |
46 |
Correct |
15 ms |
15280 KB |
Output is correct |
47 |
Correct |
13 ms |
15280 KB |
Output is correct |
48 |
Correct |
13 ms |
15308 KB |
Output is correct |
49 |
Correct |
15 ms |
15316 KB |
Output is correct |
50 |
Correct |
15 ms |
15456 KB |
Output is correct |
51 |
Correct |
13 ms |
15468 KB |
Output is correct |
52 |
Correct |
13 ms |
15468 KB |
Output is correct |
53 |
Correct |
14 ms |
15468 KB |
Output is correct |
54 |
Correct |
13 ms |
15468 KB |
Output is correct |
55 |
Correct |
34 ms |
16540 KB |
Output is correct |
56 |
Correct |
44 ms |
16832 KB |
Output is correct |
57 |
Correct |
37 ms |
17124 KB |
Output is correct |
58 |
Correct |
34 ms |
17416 KB |
Output is correct |
59 |
Correct |
51 ms |
17716 KB |
Output is correct |
60 |
Correct |
37 ms |
18016 KB |
Output is correct |
61 |
Correct |
37 ms |
18440 KB |
Output is correct |
62 |
Correct |
26 ms |
18440 KB |
Output is correct |
63 |
Correct |
18 ms |
18440 KB |
Output is correct |
64 |
Correct |
34 ms |
19068 KB |
Output is correct |
65 |
Correct |
33 ms |
19068 KB |
Output is correct |
66 |
Correct |
32 ms |
19316 KB |
Output is correct |
67 |
Correct |
22 ms |
19316 KB |
Output is correct |
68 |
Correct |
22 ms |
19316 KB |
Output is correct |
69 |
Correct |
36 ms |
19968 KB |
Output is correct |
70 |
Correct |
34 ms |
20200 KB |
Output is correct |
71 |
Correct |
535 ms |
41608 KB |
Output is correct |
72 |
Correct |
483 ms |
48136 KB |
Output is correct |
73 |
Correct |
536 ms |
53948 KB |
Output is correct |
74 |
Correct |
471 ms |
56700 KB |
Output is correct |
75 |
Correct |
604 ms |
62396 KB |
Output is correct |
76 |
Correct |
539 ms |
68144 KB |
Output is correct |
77 |
Correct |
217 ms |
68144 KB |
Output is correct |
78 |
Correct |
535 ms |
76420 KB |
Output is correct |
79 |
Correct |
501 ms |
82232 KB |
Output is correct |
80 |
Correct |
509 ms |
87936 KB |
Output is correct |
81 |
Correct |
98 ms |
87936 KB |
Output is correct |
82 |
Correct |
341 ms |
89308 KB |
Output is correct |
83 |
Correct |
553 ms |
98916 KB |
Output is correct |
84 |
Correct |
637 ms |
104696 KB |
Output is correct |
85 |
Correct |
498 ms |
110528 KB |
Output is correct |
86 |
Correct |
524 ms |
116368 KB |
Output is correct |
87 |
Correct |
526 ms |
122116 KB |
Output is correct |
88 |
Correct |
84 ms |
122116 KB |
Output is correct |
89 |
Correct |
290 ms |
122116 KB |
Output is correct |
90 |
Correct |
243 ms |
122116 KB |
Output is correct |
91 |
Correct |
45 ms |
122116 KB |
Output is correct |
92 |
Correct |
263 ms |
122116 KB |
Output is correct |