#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], dif;
int R_Do_Operations(int e, int T){
for (int i = n; i >= 2; i--){
if (t[i] - t[i - 1] <= T){
e -= a[i];
}
e = max(e, 0);
e = min(e, Vmax);
}
return e;
}
int Do_Operations(int s, int T){
for (int i = 2; i <= n; i++){
if (t[i] - t[i - 1] <= T){
s += a[i];
}
s = max(s, 0);
s = min(s, Vmax);
}
return s;
}
int ok(int T){
int s = R_Do_Operations(V2, T);
int e = Do_Operations(s, T);
return (e == 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);
if (i != 1) dif = max(dif, t[i] - t[i - 1]);
}
if (ok(dif + 1)) return cout << "infinity\n", 0;
int l = 0, r = dif + 1;
while (l + 1 < r){
int mid = (l + r) / 2;
if (ok(mid)) l = mid;
else r = mid;
}
int L = R_Do_Operations(V2, l), R = Vmax + 1;
while (L + 1 < R){
int mid = (L + R) / 2;
if (Do_Operations(mid, l) == V2) L = mid;
else R = mid;
}
cout << l << ' ' << L << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
620 KB |
Output is correct |
2 |
Correct |
16 ms |
748 KB |
Output is correct |
3 |
Correct |
21 ms |
620 KB |
Output is correct |
4 |
Correct |
15 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
67 ms |
1124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
76 ms |
1268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |