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.