SOLBLTY - Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Practice

Setter: Daanish Mahajan
Tester & Editorialist: Taranpreet Singh

DIFFICULTY

Cakewalk

PREREQUISITES

None

PROBLEM

Starting with 1 liter of water having solubility A\frac{g}{100 mL}. With each degree rise in temperature, solubility increases by B\frac{g}{100 mL}.

Determine the maximum solubility

QUICK EXPLANATION

  • The maximum solubility would be at temperature 100 degrees.
  • Simulate

EXPLANATION

Here, we have initial temperature of water, initial solubility, maximum temperature we can heat water to (100 degrees), and the additional solubility for every additional degree. We want to find maximum possible solubility.

Since we know that solubility increases as the water temperature rises, we’d want to raise the temperature as much as possible. Here, we cannot raise beyond 100 degrees.

Hence, the maximum possible solubility is the solubility at 100 degrees temperature.

In order to calculate solubility at temperature T, we can see that every rise in degree increases solubility by 10*B (Since there is 1 liter = 10*100mL water. Hence, Raising temperature from X to 100 raises solubility by (100-X)*10*B Initial solubility is 10*A

Hence, maximum solubility is 10*(A + (100-X)*B)

We can also find the same by simulating the heating process degree by degree which is also fast enough for given constraints to get AC.

TIME COMPLEXITY

The time complexity is O(1) per test case.

SOLUTIONS

Setter's Solution
#include<bits/stdc++.h>
# define pb push_back 
#define pii pair<int, int>
#define mp make_pair
# define ll long long int

using namespace std;

const int maxt = 1e3;

int main()
{   
    int t; cin >> t;
    int T, S, dS;
    while(t--){
        cin >> T >> S >> dS;
        int ans = (S + (100 - T) * dS) * 10;
        cout << ans << endl;
    }
} 
Tester's Solution
import java.util.*;
import java.io.*;
class SOLBLTY{
    //SOLUTION BEGIN
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int X = ni(), A = ni(), B = ni();
        pn(10 * (A + (100-X)*B));
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    static boolean multipleTC = true;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        new SOLBLTY().run();
    }
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }  
            return str;
        }
    }
}

Feel free to share your approach. Suggestions are welcomed as always. :slight_smile:

Easy Java Solution

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
   
	public static void main (String[] args) throws java.lang.Exception
	{
	
	        Scanner sc=new Scanner(System.in);
		int T=sc.nextInt();
		for(int a0=0;a0<T;a0++){
		    int X=sc.nextInt();             //current temperature
    		int A=sc.nextInt();             
    		int B=sc.nextInt();
    		int solubility=(A+(100-X)*B)*10;              //formula to be applied
    		System.out.println(solubility);
		}   
	}
}

Nothing to do much in this question. Simply apply the formula and you’ll get the ans🙂

I literally have the exact same code why doesn’t it work

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner s = new Scanner(System.in);
int n = s.nextInt();

	for(int i = 1; i <= n; i++){
	    int x = s.nextInt();
	    int a = s.nextInt();
	    int b = s.nextInt();
	    int final = (b*(100-x)+a)*10;
	    System.out.println(final);
	}
}

}

the final keyword is already defined in java compiler, so use some other name for your variable and it will work

    int n = s.nextInt();

	for(int i = 1; i <= n; i++){
	    int x = s.nextInt();
	    int a = s.nextInt();
	    int b = s.nextInt();
	    int res = ((b*(100-x))+a)*10;
	    System.out.println(res);
	}
1 Like

thank you its solved