#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define sh cin.tie(0); cin.sync_with_stdio(0); cout.tie(0);
#define FILE freopen("test.in", "r", stdin);
#define vprint(v) for (int ii = 0; ii < v.size(); ii++){cout << v[ii] << " ";}
#define debugv(v) if (v.size() != 0) {cout << "[ "; for (int __ = 0; __ < (int)(v.size()) - 1; __++){cout << v[__] << ", ";} cout << v[(int)(v.size()) - 1] << " ]" << endl;} else {cout << "[]" << endl;}
#define debug cout << "-----------------------------------------------" << endl;
#define print1(a) cout << "{ " << a << " }" << endl;
#define print2(a, b) cout << "{ " << a << ", " << b << " }" << endl;
#define print3(a, b, c) cout << "{ " << a << ", " << b << ", " << c << " }" << endl;
#define print4(a, b, c, d) cout << "{ " << a << ", " << b << ", " << c << ", " << d << " }" << endl;
using namespace std;
//#define int long long
const int INF = 2e9 + 228;
const int MAXN = 1e5 + 228;
int n, vm, v2;
vector<pair<int, int>> v;
pair<bool, int> check(int t) {
//print2("t", t);
bool res = 0;
int x = -1;
for (int v1 = vm; v1 >= 0; v1--) {
int nw = v1;
for (int i = 0; i < n; i++) {
if (v[i].S > t) {
continue;
}
nw += v[i].F;
nw = max(0, nw);
nw = min(vm, nw);
}
if (nw == v2) {
return {1, v1};
}
res |= (nw == v2);
}
return {res, x};
}
signed main()
{
#ifdef LOCAL
FILE;
#endif
sh;
cin >> n >> vm >> v2;
int lst = 0;
for (int i = 0; i < n; i++) {
int bb;
char aa;
cin >> aa >> bb;
int bbb = bb;
if (i == 0) {
bb = INF - 8;
}
if (aa == '-') {
v.pb({-1, bb - lst});
} else {
v.pb({1, bb - lst});
}
lst = bbb;
}
if (check(INF - 100).F) {
cout << "infinity" << endl;
return 0;
}
int mx = 0;
int ans = 0;
vector<int> k;
for (int i = 1; i < n; i++) {
k.pb(v[i].S - 1);
}
sort(all(k));
reverse(all(k));
for (int i = 1; i < n; i++) {
bool kek = 0;
int now = 0;
tie(kek, now) = check(k[i]);
//print2(kek, now);
if (kek) {
cout << k[i] << ' ' << now << endl;
return 0;
}
}
cout << mx << ' ' << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
504 KB |
Output is correct |
2 |
Execution timed out |
1090 ms |
376 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
845 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
666 ms |
504 KB |
Output is correct |
4 |
Correct |
22 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1086 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1096 ms |
760 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1099 ms |
760 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
760 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
1140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1094 ms |
2032 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1094 ms |
2140 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |