#include <bits/stdc++.h>
using namespace std;
struct Node {
int S, L, R;
};
int VMAX;
inline Node ident() { return {0, 0, VMAX}; }
inline Node leafFromOp(char c) { return {(c == '+') ? 1 : -1, 0, VMAX}; }
inline Node combine(const Node& left, const Node& right) {
Node res;
res.S = left.S + right.S;
res.L = max(left.L + right.S, right.L);
res.R = min(left.R + right.S, right.R);
return res;
}
inline int clampInt(int x, int lo, int hi) {
if (x < lo) return lo;
if (x > hi) return hi;
return x;
}
struct SegTree {
int n;
vector<Node> st;
SegTree(int n_ = 0) { init(n_); }
void init(int n_) {
n = max(1, n_);
st.assign(4 * n, ident());
}
void update(int idx, const Node& val, int p, int l, int r) {
if (l == r) { st[p] = val; return; }
int m = (l + r) >> 1;
if (idx <= m) update(idx, val, p << 1, l, m);
else update(idx, val, p << 1 | 1, m + 1, r);
st[p] = combine(st[p << 1], st[p << 1 | 1]);
}
void update(int idx, const Node& val) { update(idx, val, 1, 0, n - 1); }
Node all() const { return st[1]; }
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, V2;
if (!(cin >> N >> VMAX >> V2)) return 0;
vector<char> op(N + 1);
vector<int> t(N + 1);
for (int i = 1; i <= N; ++i) cin >> op[i] >> t[i];
if (N == 1) { cout << "infinity\n"; return 0; }
vector<pair<int,int>> byDelta;
byDelta.reserve(N - 1);
for (int i = 2; i <= N; ++i)
byDelta.emplace_back(t[i] - t[i - 1], i);
sort(byDelta.begin(), byDelta.end());
vector<int> uniqD;
uniqD.reserve(byDelta.size());
for (auto &p : byDelta)
if (uniqD.empty() || uniqD.back() != p.first) uniqD.push_back(p.first);
SegTree st(N - 1);
auto imageContains = [&](const Node& F, int v) -> bool {
int a = clampInt(F.S, F.L, F.R);
int b = clampInt(VMAX + F.S, F.L, F.R);
return a <= v && v <= b;
};
Node bestF = ident();
int best_Tright = uniqD[0] - 1;
if (!imageContains(bestF, V2)) {}
int pos = 0;
for (int g = 0; g < (int)uniqD.size(); ++g) {
int dval = uniqD[g];
while (pos < (int)byDelta.size() && byDelta[pos].first == dval) {
int i = byDelta[pos].second;
int leafIdx = i - 2;
st.update(leafIdx, leafFromOp(op[i]));
++pos;
}
Node cur = st.all();
if (imageContains(cur, V2)) {
if (g == (int)uniqD.size() - 1) {
cout << "infinity\n";
return 0;
}
bestF = cur;
best_Tright = uniqD[g + 1] - 1;
}
}
int S = bestF.S, L = bestF.L, R = bestF.R;
int V1;
if (V2 == L) V1 = min(VMAX, L - S);
else if (V2 == R) V1 = VMAX;
else V1 = V2 - S;
cout << best_Tright << ' ' << V1 << '\n';
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |