// UVa 11627 - Slalom
#include <algorithm>
#include <stdio.h>
using namespace std;
#define ll signed long long int
double epsilon = 1e-10;
ll x[100000], y[100000], s[1000000];
ll w, v;
int n, m;
bool possible(ll s) {
ll x1 = x[0] * s;
ll x2 = (x[0] + w) * s;
for (int i = 1; i < n; i++) {
ll move = (y[i] - y[i - 1]) * v;
ll xl = x1 - move;
ll xr = x2 + move;
x1 = max(x[i] * s, xl);
x2 = min((x[i] + w) * s, xr);
if (x1 > x2)
return false;
}
return true;
}
ll bsearch(ll ini, ll fin) {
if (ini > fin)
return -1;
if (ini == fin) {
if (possible(s[ini]))
return ini;
else
return -1;
}
ll mid = (ini + fin + 1) / 2;
if (possible(s[mid]))
return bsearch(mid, fin);
else
return bsearch(ini, mid - 1);
}
int main() {
int t;
for (scanf("%d", &t); t; t--) {
scanf("%lld%lld%d", &w, &v, &n);
for (int i = 0; i < n; i++)
scanf("%lld%lld", &x[i], &y[i]);
scanf("%d", &m);
for (int i = 0; i < m; i++)
scanf("%lld", &s[i]);
sort(s, s + m);
ll sol = bsearch(0, m - 1);
if (sol == -1)
printf("IMPOSSIBLE\n");
else
printf("%lld\n", s[sol]);
}
return 0;
}
Saturday, May 16, 2015
UVa 11627 - Slalom
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment