Monday 9 March 2020

Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)

A. Contest for Robots
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets pi points, and the score of each robot in the competition is calculated as the sum of pi over all problems i solved by it. For each problem, pi is an integer not less than 1.
Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results — or manipulating them.
For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of pi in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of pi will be large, it may look very suspicious — so Polycarp wants to minimize the maximum value of pi over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?
Input
The first line contains one integer n (1n100) — the number of problems.
The second line contains n integers r1r2, ..., rn (0ri1). ri=1 means that the "Robo-Coder Inc." robot will solve the i-th problem, ri=0 means that it won't solve the i-th problem.
The third line contains n integers b1b2, ..., bn (0bi1). bi=1 means that the "BionicSolver Industries" robot will solve the i-th problem, bi=0 means that it won't solve the i-th problem.
Output
If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer 1.
Otherwise, print the minimum possible value of maxi=1npi, if all values of pi are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.
Examples
input
Copy
5
1 1 1 0 0
0 1 1 1 1
output
Copy
3
input
Copy
3
0 0 0
0 0 0
output
Copy
-1
input
Copy
4
1 1 1 1
1 1 1 1
output
Copy
-1
input
Copy
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
output
Copy
4
Note
In the first example, one of the valid score assignments is p=[3,1,3,1,1]. Then the "Robo-Coder" gets 7 points, the "BionicSolver" — 6 points.
In the second example, both robots get 0 points, and the score distribution does not matter.
In the third example, both robots solve all problems, so their points are equal.
Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,ar[109],br[109],a,b,ans;
    while(cin>>n)
    {
        a=0;
        for(i=0; i<n; i++)
        {
            cin>>ar[i];
            a+=ar[i];
        }
        b=0;
        for(i=0; i<n; i++)
        {
            cin>>br[i];
            if(ar[i]!=1)
                b+=br[i];
            if(ar[i]==1&&br[i]==1)
                a--;
        }
        //cout<<a<<" "<<b<<endl;
        b=b+1;
        if(a!=0)
        {
            ans=b/a;
            //cout<<"a1="<<ans<<endl;
            if(b%a!=0)
                ans+=1;
            cout<<ans<<endl;
        }
        else
            cout<<-1<<endl;
    }
}

No comments:

Post a Comment