QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625761 | #9427. Collect the Coins | nhat2004 | WA | 0ms | 3616kb | C++20 | 1.4kb | 2024-10-09 20:53:32 | 2024-10-09 20:53:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct coin1 {
int timer, pos;
};
int n;
coin1 coin[1000006];
int check(int k) {
pair<int, int> robot[2];
robot[0].first = -1e18;
robot[0].second = 1e18;
for (int i = 1; i <= n; i++) {
int t = coin[i].timer, c = coin[i].pos;
int l = c - (t - coin[i-1].timer) * k;
int r = c + (t - coin[i-1].timer) * k;
robot[0].first = max(robot[0].first, l);
robot[0].second = min(robot[0].second, r);
if (robot[0].first > robot[0].second) {
return 0;
}
}
return 1;
}
bool cmp(coin1 a, coin1 b) {
if (a.timer != b.timer) {
return a.timer < b.timer;
} else {
return a.pos < b.pos;
}
}
signed main() {
int tc;
cin >> tc;
while (tc--) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> coin[i].timer >> coin[i].pos;
}
sort(coin + 1, coin + 1 + n, cmp);
int l = 0, r = 1e9, res = -1;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) {
res = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
cout << res << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
3 5 1 1 3 7 3 4 4 3 5 10 1 10 100 3 10 100 10 1000 10 10000
output:
6 0 -1
result:
wrong answer 1st lines differ - expected: '2', found: '6'