GOLMINE - Editorial

Used that also but it didn’t work.

One of the most controversial question it seems.

I faced the exact same issue. I overcomplicated it and discarded the idea of them working in the same mine at all times and ended up messing up the whole constest.

Why is this wrong ?

Here

1 Like

How could they possibly not get anything? Their moves are instantaneous. The sum of the total amount of gold that they get is always equal to the total amount of gold that was in the mines. They are always in a nonempty mine, so after any nonzero amount of time they must have mined some nonzero amount of gold. I made some other posts to discuss this here and here.

the lemma is correct but the proof is incorrect. let me try to give another proof.
in this explanation i am talking about total gold extracted in all n mines and not of a single mine.
their is one possible answer according to lemma say Chef and Chefu get x and y gold respectively. now let us assume one got another answer as x+a gold and y-a gold. now chefu got less gold than y so he will try to gain at least y gold by forcefully working in same mine where chef is. now the point is that for working together in mine it is sufficient that only one of them decide to work together then other have no option. if the other person tries to change mine, the first person can come to same mine instantaneously. also the idea that they will keep on changing mine indefinitely is rubbish as they can shift to all mines billions of times in 0 sec . so at last they have to work together if at least one of them want to work together.
so by this idea both chef and chefu can maintain at least x and y gold and since x+y is constant , therefore x and y is the only answer.

how (edit : i got it, thanks ) :rofl: :rofl: :rofl:. you’re genious.

1 Like

But if Chef has more than one choice of mine where he outperforms Chefu, he can immediately move to the one where Chefu isn’t.

How do you now decide whether they’re in the same mine or different mines, when each is switching mine infinitely many times per second?

This whole problem seems to have been a “trick question where you’ve got to approach it the same way as me or you get Wrong Answer”… even the test cases were bad, as they didn’t include ANY cases where Chef and Chefu had different mining rates… so we had to make our own test cases based on our own assumptions about what constitutes “optimal”, which it seems many interpreted as “optimise your own mining speed, keeping an eye out for where your competitor will be if there’s a choice”. We were given zero opportunity to discover we’d made different assumptions to the problem setter before submitting and getting a “wrong answer”, and zero opportunity to discover what the correct assumptions were based on a known test case.

take this input :-

3
10 1 4
10 2 3
10 3 1

if they work in the mines where they extract max gold/day rate first then procedure will go like
rates would be like

player 1          player 2
    10              2.5
    5               3.33
    3.33            10

player 2 will go to 3rd mine first then 2nd and then 1st
player 1 will go to 1st mine first then 2nd and then 3rd

after day one both will have 10 gold each and only 2nd mine is remaining to mine (as both have gathered 10 from 1st and 3rd)
and on second they both wont be able to gather same on that day as now their rates are different
final score would be player 1 : with 16 and player 2 with 14.

but what if you go with working in same mines at time :

        p1    p2
mine1    8     2
mine2    14    6
mine3    16.5  13.5

test cases were wrong indeed so…

I don’t see anything wrong with the problem statement. It might be lack of understanding from your side. Don’t blame the setters for your mistake or leave this platform if you find problem statements here “poorly constructed”.

Okay I see one reply from kingofnumber. Do you agree with him ?

I have written the code in 2 languges, the logic being same, one in C++ and another in JAVA. Can please comeone tell my why the C++ code is giving WA while the JAVA code is correct? Thank you in advance. Below are the two code

/JAVA/
Link: CodeChef: Practical coding for everyone

import java.util.;
import java.io.
;
class GOLMINE{
static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(InputStream stream) {
try {
br = new BufferedReader(new
InputStreamReader(stream));
} catch (Exception e) {
e.printStackTrace();
}
}

    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    String nextLine() {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
    long nextLong() {
        return Long.parseLong(next());
    }
    double nextDouble() {
        return Double.parseDouble(next());
    }
 }
 public static void main(String args[]){
      try{
           FastScanner sc=new FastScanner(System.in);
           int t=sc.nextInt();
           while(t-->0){
                int n=sc.nextInt();
                double g,a,b;
                double ga=0.0,gb=0.0;
                for(int i=0; i<n; i++){
                    g=sc.nextDouble();
                    a=sc.nextDouble();
                    b=sc.nextDouble();
                    ga += (b*g) / (a+b);
                    gb += (a*g) / (a+b);
                }
                System.out.println(ga+" "+gb);
           }
      }catch(Exception e){}
 }

}

/********************** C++ **********************/
Link: CodeChef: Practical coding for everyone

#include
#include
#include
#include <bits/stdc++.h>
#include <stdbool.h>
#include <math.h>
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define show(x) cout << (#x) << " : " << x << endl;
#define forn(i,a,b) for(int (i)=(a);(i) < (b); (i)++)
using namespace std;

void solve(){
int n;
cin >> n;
double ga=0.0,gb=0.0;
double g[n],a[n],b[n];
forn(i,0,n){
cin >> g[i] >> a[i] >> b[i];
}
forn(i,0,n){
ga+= (b[i]/(b[i]+a[i])) * g[i];
gb+= (a[i]/(b[i]+a[i]) )* g[i];
}
cout << ga << " " << gb << endl;
}

int main() {
fastio();
int nooftestcases;
cin >> nooftestcases;
forn(i,0,nooftestcases){
solve();
}
return 0;
}

Although when I am adding setprecision(6) its working,
WORKING C++ CODE

/********************** C++ **********************/
Link: CodeChef: Practical coding for everyone

#include
#include
#include
#include <bits/stdc++.h>
#include <stdbool.h>
#include <math.h>
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define show(x) cout << (#x) << " : " << x << endl;
#define forn(i,a,b) for(int (i)=(a);(i) < (b); (i)++)
using namespace std;

void solve(){
int n;
cin >> n;
double ga=0.0,gb=0.0;
double g[n],a[n],b[n];
forn(i,0,n){
cin >> g[i] >> a[i] >> b[i];
}
forn(i,0,n){
ga+= (b[i]/(b[i]+a[i])) * g[i];
gb+= (a[i]/(b[i]+a[i]) )* g[i];
}
cout << fixed << setprecision(6)<< ga << " " << gb << endl;
}

int main() {
fastio();
int nooftestcases;
cin >> nooftestcases;
forn(i,0,nooftestcases){
solve();
}
return 0;
}

It might be lack of understanding from your side

I never said that I misunderstood the problem statement, but I had to read it over 10 times to get what the question said. Thus, I felt that the problem statement is poorly constructed.

Don’t blame the setters for your mistake

How is this my mistake? And I never blamed the setters. I just said that the statements were poorly constructed, and setters should take care. If you don’t understand stuff, don’t post irrelevant things please.

leave this platform if you find problem statements here “poorly constructed”.

Why shall I leave the platform for one statement? And you are no one to take my decisions.

Saying this, I bet you haven’t read the statement I had made more than once. Try reading it again, maybe then you will understand what I meant.

There were several arguments that it would be optimal for both Chef and Chefu to be in the mine with the maximum \frac{G_i}{A_i + B_i}. I find kingofnumber’s argument to be the most convincing. The only potential issue I see with it is that it assumes for every time t, there is some positive dt such that no switching happens between times t and t + dt. If there’s some nonempty time interval where there is switching at every instant in that time interval (if that even makes any sense mathematically), then no matter how small dt is there would be switching before t and t + dt. Other than that, I think it’s a solid proof.

Use long double instead of double.
My solution:

#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector <long double> g(n), a(n), b(n);
        for (int i = 0; i < n; ++i) cin >> g[i] >> a[i] >> b[i];
        long double aans = 0, bans = 0;
        for (int i = 0; i < n; ++i)
        {
            bans += ((g[i]*a[i])/(a[i]+b[i]));
            aans += ((g[i]*b[i])/(a[i]+b[i]));
        }
        cout << fixed << setprecision(5) << aans << " ";
        cout << fixed << setprecision(5) << bans << '\n';
    }
}

Can someone please debug my piece of code??Its giving TLE…

Use fast i/o

dont use endl ‘\n’ is much more faster.

My solution is CodeChef: Practical coding for everyone
I am getting a TLE can anyone please explain why?