QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#623458 | #9427. Collect the Coins | ptit_noodles | RE | 0ms | 0kb | C++14 | 1.5kb | 2024-10-09 12:07:26 | 2024-10-09 12:07:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define ii pair<int, int>
const int N = 2e6+5, M = 1e3+5, inf = 1e18, MOD = 1e9+7;
int n, m, x, y, res, test, k, sum1, cnt;
int t[N], c[N], l[N], r[N];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> test;
while (test--) {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> t[i] >> c[i];
l[1] = r[n] = 0; res = 0;
for (int i = 2; i <= n; ++i) {
if (i > 2 && t[i] == t[i - 1] && t[i] == t[i - 2]) res = -1;
if (abs(c[i] - c[i - 1]) % (t[i] - t[i - 1]) == 0) x = (int)abs(c[i] - c[i - 1]) / (int)(t[i] - t[i - 1]);
else x = (int) abs(c[i] - c[i - 1]) / (int)(t[i] - t[i - 1]) + 1;
l[i] = max(l[i - 1], x);
}
for (int i = n - 1; i > 0; --i) {
if (abs(c[i] - c[i + 1]) % (t[i + 1] - t[i]) == 0) x = (int)abs(c[i] - c[i + 1]) / (int)(t[i + 1] - t[i]);
else x = (int)abs(c[i] - c[i + 1]) / (int)(t[i + 1] - t[i]) + 1;
r[i] = max(r[i + 1], x);
}
// for (int i = 1; i <= n; ++i) cout << l[i] << ' '; cout << endl;
// for (int i = 1; i <= n; ++i) cout << r[i] << ' '; cout << endl;
if (res == -1) cout << res << endl;
else {
res = (n == 1 ? 0 : inf);
for (int i = 1; i < n; ++i) res = min(res, max(l[i], r[i + 1]));
cout << res << endl;
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 5 1 1 3 7 3 4 4 3 5 10 1 10 100 3 10 100 10 1000 10 10000