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

Is Desk Productivity Tools...

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

The Outer Worlds 2...

Gamers and RPG enthusiasts have reason to celebrate as...

Why Travel Organization Gear...

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

Why Everyone Is Talking...

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

Why Everyone Is Talking...

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

Why Everyone Is Talking...

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

Is Desk Productivity Tools Worth Your Money Here Is Our Full Review

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Desk Productivity Tools?The Desk Productivity Tools...

The Outer Worlds 2 v1.2.0.1-TENOKE

Gamers and RPG enthusiasts have reason to celebrate as Obsidian Entertainment's acclaimed franchise returns with new developments. The highly anticipated sequel to the award-winning...

Why Travel Organization Gear Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Travel Organization Gear?The Travel Organization Gear...

Why Everyone Is Talking About the Car Detailing Essentials

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Car Detailing Essentials?The Car Detailing Essentials...

Why Everyone Is Talking About the Smart Home Hacks

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Smart Home Hacks?The Smart Home Hacks...

Why Everyone Is Talking About the Viral Kitchen Gadgets

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Viral Kitchen Gadgets?The Viral Kitchen Gadgets...

Why Everyone Is Talking About the Travel Organization Gear

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Travel Organization Gear?The Travel Organization Gear...

Why Everyone Is Talking About the Travel Organization Gear

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Travel Organization Gear?The Travel Organization Gear...

GLP-1 Drugs Like Ozempic Carry Elevated Risks of Muscle Loss and Malnutrition in Adults Over 65

Understanding the Risks of GLP-1 Drugs for Older Adults GLP-1 receptor agonists, such as Ozempic, Wegovy, and Mounjaro, have transformed the landscape of weight management...