Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3), problem: (D) Dynamic Problem Scoring Solution In C/C++

#include<bits/stdc++.h>
using namespace std;
int a[150][150];
int cnt[10];
int n;
int getsc(int id, bool f, int s) {
if(a[f][id]==-1) return 0;
int sum;
if(a[0][id] == -1 || a[1][id] == -1 || a[0][id]<a[1][id]) sum = cnt[id];
else sum = cnt[id]+s;
int sc = 500;
for(int i = 2; i <= 32; i*=2) {
if(sum*i > n+s)
break;
else sc += 500;
}
return sc*(250.0 – a[f][id])/250.0;
}
int main() {
cin >> n;
for(int i = 0; i < n; ++i)
for(int j = 0; j < 5; ++j) {
cin >> a[i][j];
if(a[i][j]!= -1)
cnt[j]++;
}
for(int i = 0; i < 50000; ++i) {
int a1=0, a2=0;
for(int j = 0; j < 5; ++j)
a1 += getsc(j, 0, i);
for(int j = 0; j < 5; ++j)
a2 += getsc(j, 1, i);
if(a1 > a2) {
cout << i << endl;
return 0;
}
}
cout << “-1” <<endl;
return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[150][150];
int cnt[10];
int n;
int getsc(int id, bool f, int s) {
if(a[f][id]==-1) return 0;
int sum;
if(a[0][id] == -1 || a[1][id] == -1 || a[0][id]<a[1][id]) sum = cnt[id];
else sum = cnt[id]+s;
int sc = 500;
for(int i = 2; i <= 32; i*=2) {
if(sum*i > n+s)
break;
else sc += 500;
}
return sc*(250.0 – a[f][id])/250.0;
}
int main() {
cin >> n;
for(int i = 0; i < n; ++i)
for(int j = 0; j < 5; ++j) {
cin >> a[i][j];
if(a[i][j]!= -1)
cnt[j]++;
}
for(int i = 0; i < 50000; ++i) {
int a1=0, a2=0;
for(int j = 0; j < 5; ++j)
a1 += getsc(j, 0, i);
for(int j = 0; j < 5; ++j)
a2 += getsc(j, 1, i);
if(a1 > a2) {
cout << i << endl;
return 0;
}
}
cout << “-1” <<endl;
return 0;
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Anker 622 MagGo Magnetic Battery: 2026 Review, Specs & Worth-It Verdict

Anker 622 MagGo Magnetic Battery: Is the Hype Worth It in 2026? The Anker 622 MagGo Magnetic Battery has been climbing Amazon's Movers & Shakers...

Apple AirPods Pro 2 USB-C: 2026 Review, Specs & Worth-It Verdict

Apple AirPods Pro 2 USB-C: Is the Hype Worth It in 2026? The Apple AirPods Pro 2 USB-C has been climbing Amazon's Movers & Shakers...

Owala FreeSip Insulated Water Bottle 24oz: 2026 Review, Specs & Worth-It Verdict

Owala FreeSip Insulated Water Bottle 24oz: Is the Hype Worth It in 2026? The Owala FreeSip Insulated Water Bottle 24oz has been climbing Amazon's Movers...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!