이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x))
using namespace std;
int main() {
#ifdef HOME
ifstream cin("C.in");
ofstream cout("C.out");
#endif
int i, n, s;
ll k;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> s >> k;
vector<ll> x(n + 1), v(n + 1);
for(i = 2; i <= n; i++) {
int d; cin >> d;
x[i] = x[i - 1] + d;
}
for(i = 1; i <= n; i++) {
cin >> v[i];
v[i] += v[i - 1];
}
vector<vector<int>> anc(20, vector<int>(n + 1));
vector<int> nxt(n + 1);
int a = 1, b = 1;
for(i = 1; i <= n; i++) {
while(a <= n && x[a] - x[i] <= k) {
a++;
}
nxt[i] = a - 1;
while(b <= n && x[b] - x[a] <= k) {
b++;
}
anc[0][i] = b - 1;
}
for(int bit = 1; bit < 20; bit++) {
for(i = 1; i <= n; i++) {
anc[bit][i] = anc[bit - 1][anc[bit - 1][i]];
}
}
x[0] = 1e18;
int id, l = 1;
ll ans = 0;
for(i = 1; i <= n; i++) {
while(x[i] - x[l] > k) {
l++;
}
int r = i;
for(int bit = 19; bit >= 0; bit--) {
if((s - 1) & (1 << bit)) {
r = anc[bit][r];
}
}
r = nxt[r];
//cerr << i << " " << l << " " << r << "\n";
if(ans < v[r] - v[l - 1]) {
ans = v[r] - v[l - 1];
id = i;
}
}
vector<int> sol;
while(s > 0 && id != 0) {
sol.push_back(id);
id = anc[0][id];
s--;
}
cout << sol.size() << "\n";
for(auto it : sol) {
cout << it << " ";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |