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;
}

Advertisement

spot_img

Stop Buying Cheap Alternatives...

📢 As an Amazon Associate, I earn from qualifying...

Why Viral Kitchen Gadgets...

📢 As an Amazon Associate, I earn from qualifying...

Why Viral Kitchen Gadgets...

📢 As an Amazon Associate, I earn from qualifying...

How Viral Kitchen Gadgets...

📢 As an Amazon Associate, I earn from qualifying...

Science of a city:...

When we discuss the world’s greatest metropolises, the conversation...

Stop Buying Cheap Alternatives...

📢 As an Amazon Associate, I earn from qualifying...

Stop Buying Cheap Alternatives This Viral Kitchen Gadgets Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Viral Kitchen Gadgets through a proper 30-day real-world test, I can tell...

Why Viral Kitchen Gadgets Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.If you had told me six months ago that a single purchase would change how...

Why Viral Kitchen Gadgets Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....

How Viral Kitchen Gadgets Is Quietly Changing the Game

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Viral Kitchen Gadgets through a proper 30-day real-world test, I can tell...

Science of a city: The maths, physics, ecology & psychology of urban life

When we discuss the world’s greatest metropolises, the conversation almost invariably revolves around politics, zoning regulations, and economic indicators. Yet, beneath the concrete grid...

Stop Buying Cheap Alternatives This Viral Kitchen Gadgets Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.If you had told me six months ago that a single purchase would change how...

Pip Edwards turns heads at Derby Day in a very bizarre headpiece – as she shares rare update on new romance with boyfriend Nicholas...

Fashion entrepreneur Pip Edwards knows exactly how to command attention, and her latest appearance at Flemington Racecourse proved to be no exception. Stepping out...

Why Viral Kitchen Gadgets Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.After putting the Viral Kitchen Gadgets through a proper 30-day real-world test, I can tell...

Sensex, Nifty may gain 5-8% if external headwinds recede: Baldev Prakash

The Indian equity benchmarks, Sensex and Nifty, could witness a notable rebound of 5% to 8% in the near term provided persistent external headwinds...