#include <bits/stdc++.h>
using namespace std;
void main_program();
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
main_program();
}
#define int long long
int n, k;
vector<int> Ws;
vector<int> lst;
bool check(int threshold){
lst.clear();
int prev = -(int)1e16, wait = (int)1e16;
int crr = 0;
for (int i = 0; i < n; i++){
if (crr - prev > threshold){
wait = min(wait, crr);
if (i < n-1){
int newcrr = crr + Ws[i];
if (newcrr - wait > threshold){
lst.push_back(i);
prev = crr;
wait = (int)1e16;
}
}
}
if (i < n-1) crr += Ws[i];
}
if (wait < (int)1e16) lst.push_back(n-1);
return (int)lst.size() <= k;
}
void main_program(){
// Sub 3
cin >> n >> k;
Ws.resize(n-1);
for (int i = 0; i < n-1; i++){
int x, y, w; cin >> x >> y >> w;
Ws[i] = w;
}
int l = 0, r = 1e15;
while (l < r){
int mid = (l + r) >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}
check(l);
cout << l << "\n";
vector<int> mark(n);
for (auto i: lst){
mark[i] = 1; k--;
}
for (int i = 0; i < n; i++){
if (!mark[i] && k){
mark[i] = 1; k--;
}
}
for (int i = 0; i < n; i++){
if (mark[i]) cout << i+1 << " ";
}
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
3472 KB |
Output is correct |
2 |
Correct |
73 ms |
3484 KB |
Output is correct |
3 |
Incorrect |
79 ms |
3660 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
3512 KB |
Output is correct |
2 |
Correct |
79 ms |
3672 KB |
Output is correct |
3 |
Correct |
80 ms |
3524 KB |
Output is correct |
4 |
Correct |
87 ms |
3564 KB |
Output is correct |
5 |
Correct |
98 ms |
6464 KB |
Output is correct |
6 |
Correct |
134 ms |
5220 KB |
Output is correct |
7 |
Correct |
130 ms |
5744 KB |
Output is correct |
8 |
Correct |
90 ms |
3672 KB |
Output is correct |
9 |
Correct |
80 ms |
3724 KB |
Output is correct |
10 |
Correct |
86 ms |
3604 KB |
Output is correct |
11 |
Correct |
72 ms |
3520 KB |
Output is correct |
12 |
Correct |
117 ms |
6612 KB |
Output is correct |
13 |
Correct |
119 ms |
9272 KB |
Output is correct |
14 |
Correct |
117 ms |
8364 KB |
Output is correct |
15 |
Correct |
69 ms |
6080 KB |
Output is correct |
16 |
Correct |
71 ms |
5844 KB |
Output is correct |
17 |
Correct |
84 ms |
5832 KB |
Output is correct |
18 |
Correct |
75 ms |
6168 KB |
Output is correct |
19 |
Correct |
84 ms |
8644 KB |
Output is correct |
20 |
Correct |
81 ms |
8260 KB |
Output is correct |
21 |
Correct |
80 ms |
7780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |