Codeforces Round #379 (Div. 2), problem: (C) Anton and Making Potions Solution in C

Hey guys I just tried the Anton and Making Potions problem , hope you might like my solution feel free to comment better solution .

#include

#define N 200000

struct type2 {
int c, d;
} yy[N];

int binsearch(struct type2 *yy, int x, int k) {
int l = -1, r = k;

while (r – l > 1) {
int m = (l + r) / 2;

if (yy[m].d > x)
r = m;
else
l = m;
}
return l;
}

int main() {
int i, n, m, k, x, s;
long long min;
static int aa[N], bb[N];

scanf(“%d%d%d%d%d”, &n, &m, &k, &x, &s);
for (i = 0; i < m; i++) scanf("%d", &aa[i]); for (i = 0; i < m; i++) scanf("%d", &bb[i]); for (i = 0; i < k; i++) scanf("%d", &yy[i].c); for (i = 0; i < k; i++) scanf("%d", &yy[i].d); for (i = 0; i < k; i++) if (yy[i].d > s)
break;
i–;
if (i >= 0)
min = (long long) (n – yy[i].c) * x;
else
min = (long long) n * x;
for (i = 0; i < m; i++) { int j; if (bb[i] > s)
continue;
j = binsearch(yy, s – bb[i], k);
if (j >= 0) {
long long t = (long long) aa[i] * (n – yy[j].c);

if (min > t)
min = t;
} else {
long long t = (long long) aa[i] * n;

if (min > t)
min = t;
}
}
printf(“%lld\n”, min);
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *