#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;
const int mxn = 1e6 + 5;
int p[mxn], vp[mxn];
pii bounds[mxn]; int up[mxn][21]; int sroot[mxn]; vi adj[mxn];
int sv(int l, int r) {
return vp[r + 1] - vp[l];
}
int sex(int st) {
int ans = sv(bounds[st].fi, bounds[st].se);
if (bounds[up[st][0]].fi <= bounds[st].se) ans -= sv(bounds[st].se, bounds[up[st][0]].fi);
return ans;
}
void dfs(int node, int prev) {
sroot[node] = sroot[prev] + sex(node);
for (auto &neighbour : adj[node]) {
if (neighbour == prev) continue;
dfs(neighbour, node);
}
}
int kanc(int node, int k) {
for (int i = 0; i < 21; i++) {
if (k & (1 << i)) node = up[node][i];
}
return node;
}
inline void solve() {
// input
int n, s, k;
cin >> n >> s >> k;
for (int i = 0; i < n - 1; i++) cin >> p[i + 1];
for (int i = 1; i < n; i++) p[i] += p[i - 1];
for (int i = 0; i < n; i++) cin >> vp[i + 1];
for (int i = 1; i <= n; i++) vp[i] += vp[i - 1];
// calculate bounds
for (int t = 0; t < n; t++) {
int lo = t;
int hi = n;
while (hi > lo + 1) {
int mid = (lo + hi) / 2;
if (p[mid] - p[t] > k) hi = mid;
else lo = mid;
}
int r = lo;
int l;
if (p[t] <= k) l = 0;
else {
int lo = 0;
int hi = t;
while (hi > lo + 1) {
int mid = (lo + hi) / 2;
if (p[t] - p[t-mid] > k) hi = mid;
else lo = mid;
}
l = t-lo;
}
bounds[t] = {l, r};
//cout << t << " bounds " << l << " -> " << r << '\n';
}
bounds[n] = {1e18, 1e18};
// find next segment
for (int st = 0; st < n; st++) {
int nxt;
if (bounds[st].se != n - 1 && bounds[st + 1].fi <= bounds[st].se + 1) {
int lo = st;
int hi = n;
while (hi > lo + 1) {
int mid = (lo + hi) / 2;
if (bounds[mid].fi <= bounds[st].se + 1) lo = mid;
else hi = mid;
}
nxt = lo;
} else {
nxt = n;
}
up[st][0] = nxt;
}
for (int i = 0; i < n; i++) {
adj[up[i][0]].pb(i);
adj[i].pb(up[i][0]);
}
dfs(n - 1, n);
for (int i = 0; i < 21; i++) {
up[n][i] = n;
}
for (int l = 1; l < 21; l++) {
for (int i = 0; i < n; i++) {
up[i][l] = up[up[i][l - 1]][l - 1];
}
}
pii ans = {-100, -1};
for (int i = 0; i < n; i++) {
int high = kanc(i, s - 1);
if (high == n) {
ans = max(ans, {sroot[i] - sex(n - 1) + sv(bounds[n - 1].fi, bounds[n - 1].se), i});
} else {
ans = max(ans, {sroot[i] - sroot[up[high][0]] - sex(high) + sv(bounds[high].fi, bounds[high].se), i});
}
}
vi answer; int cur = ans.se; for (int i = 0; i < s; i++) {
if (cur == n) break;
answer.pb(cur);
cur = up[cur][0];
}
cout << answer.size() << '\n';
for (auto &x : answer) cout << x + 1 << " ";
cout << '\n';
}
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
//setIO();
int t = 1;
if (tc) {
cin >> t;
}
while (t--) {
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
SolarStorm.cpp: In function 'void setIO(std::string)':
SolarStorm.cpp:158:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
158 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SolarStorm.cpp:159:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
159 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |