#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 = 2e9 + 10;
int n, Vmax, V2, a[N], t[N];
int ok(ll T, bool f){
int V1 = V2;
for (int i = n; i >= 2; i--){
if (t[i] - t[i - 1] <= T){
V1 -= a[i];
}
V1 = max(V1, 0);
V1 = min(V1, Vmax);
}
for (int i = 2; i <= n; i++){
if (t[i] - t[i - 1] <= T){
V1 += a[i];
}
V1 = max(V1, 0);
V1 = min(V1, Vmax);
}
if (f) return V1;
else return (V1 == V2);
}
int main (){
cin >> n >> Vmax >> V2;
for (int i = 1; i <= n; i++){
char c;
cin >> c >> t[i];
a[i] = (c == '+' ? 1 : -1);
}
int v1 = V2;
for (int i = n; i >= 1; i--){
v1 -= a[i];
v1 = max(v1, 0);
v1 = min(v1, Vmax);
}
for (int i = 1; i <= n; i++){
v1 += a[i];
v1 = max(v1, 0);
v1 = min(v1, Vmax);
}
if (v1 == V2) return cout << "infinity\n", 0;
int l = 0, r = INF;
while (l + 1 < r){
int mid = (l + r) / 2;
if (ok(mid, 0)) l = mid;
else r = mid;
}
cout << l << ' ' << ok(l, 1) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
1124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
1124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |