This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long int
#define F first
#define S second
#define pb push_back
const ll N = 1e5 + 5;
const ll LOG = 30;
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 10;
ll n, Vmax, V2, a[N], t[N], dif;
ll R_Do_Operations(ll e, ll T){
for (ll i = n; i >= 2; i--){
if (t[i] - t[i - 1] <= T){
e -= a[i];
}
e = max(e, 0ll);
e = min(e, Vmax);
}
return e;
}
ll Do_Operations(ll s, ll T){
for (ll i = 2; i <= n; i++){
if (t[i] - t[i - 1] <= T){
s += a[i];
}
s = max(s, 0ll);
s = min(s, Vmax);
}
return s;
}
int ok(ll T){
ll s = R_Do_Operations(V2, T);
ll e = Do_Operations(s, T);
return (e == V2);
}
int main (){
cin >> n >> Vmax >> V2;
for (ll i = 1; i <= n; i++){
char c;
cin >> c >> t[i];
a[i] = ((c == '+') ? 1 : -1);
if (i != 1) dif = max(dif, t[i] - t[i - 1]);
}
ll en = V2;
for (int i = n; i >= 1; i--){
en -= a[i];
en = max(en, 0ll);
en = min(en, Vmax);
}
for (ll i = 1; i <= n; i++){
en += a[i];
en = max(en, 0ll);
en = min(en, Vmax);
}
if (en == V2){
cout << "infinity\n";
return 0;
}
ll l = 0, r = INF;
while (l + 1 < r){
ll mid = (l + r) / 2;
if (ok(mid)) l = mid;
else r = mid;
}
if (dif <= l){
cout << "infinity\n";
return 0;
}
ll L = R_Do_Operations(V2, l), R = INF;
while (L + 1 < R){
ll mid = (L + R) / 2;
if (Do_Operations(mid, l) == V2) L = mid;
else R = mid;
}
cout << l << ' ' << min(L, Vmax) << '\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... |