Codeforces Round #379 (Div. 2), problem: (F) Anton and School Solution in C/C++

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

 

#include <stdio.h>

#define N 200000
#define B 30

int main() {
int i, j, n;
long long sum;
static int aa[N], bb[N], cc[N], kk[B];

scanf(“%d”, &n);
sum = 0;
for (i = 0; i < n; i++) {
scanf(“%d”, &bb[i]);
sum += bb[i];
}
for (i = 0; i < n; i++) {
scanf(“%d”, &cc[i]);
sum += cc[i];
}
if (sum % (2 * n) != 0) {
printf(“-1\n”);
return 0;
}
sum /= 2 * n;
for (i = 0; i < n; i++) {
int a = bb[i] + cc[i];

if (a < sum) {
printf(“-1\n”);
return 0;
}
a -= sum;
if (a % n != 0) {
printf(“-1\n”);
return 0;
}
aa[i] = a / n;
}
for (i = 0; i < n; i++)
for (j = 0; j < B; j++)
if ((aa[i] & 1 << j) > 0)
kk[j]++;
for (i = 0; i < n; i++) {
long long b, c;

b = c = 0;
for (j = 0; j < B; j++)
if ((aa[i] & 1 << j) > 0) {
b += (long long) (1 << j) * kk[j];
c += (long long) (1 << j) * n;
} else {
b += (long long) (1 << j) * 0;
c += (long long) (1 << j) * kk[j];
}
if (b != bb[i] || c != cc[i]) {
printf(“-1\n”);
return 0;
}
}
for (i = 0; i < n; i++)
printf(“%d “, aa[i]);
printf(“\n”);
return 0;
}

 

Everything Discussed During The...

Strategy game publisher and developer Slitherine recently hosted its...

Everything You Need to...

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

Russ Allbery: Review: Radiant...

Science fiction enthusiasts and literary critics alike are turning...

Why Pet Travel Gear...

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

Mall Together-TENOKE

Simulation gaming enthusiasts have a fresh operational challenge to...

7 Reasons This Coffee...

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

Everything Discussed During The Slitherine Next 2026 Event

Strategy game publisher and developer Slitherine recently hosted its dedicated digital showcase, Slitherine Next 2026, delivering an action-packed presentation tailored specifically for tactics enthusiasts...

Everything You Need to Know About Rechargeable Home Tech Right Now

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

Russ Allbery: Review: Radiant Star

Science fiction enthusiasts and literary critics alike are turning their eyes toward the upcoming release of Radiant Star, the latest novel by award-winning author...

Why Pet Travel Gear Is Currently Breaking the Internet

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

Mall Together-TENOKE

Simulation gaming enthusiasts have a fresh operational challenge to tackle with the arrival of Mall Together-TENOKE. This brand-new release delivers an immersive shopping mall...

7 Reasons This Coffee Bar Accessories Is Worth Every Single Penny

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Why Kitchen Organization Tools Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Is Dorm Room Hacks Worth Your Money Here Is Our Full Review

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

Stop Buying Cheap Alternatives This Camping Essentials Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...