PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Setter: Raj Khandor
Tester: Radoslav Dimitrov
Editorialist: Taranpreet Singh
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Chef works A_i hours a day in the office for i-th day in a week. He works only for 5 weekdays. If he works from home, one hour work in office takes him P hours.
For the upcoming week, he has to work from home, he wants to know whether he’d have to work on weekends to complete his work or not.
Note that Chef can work 24 hours a day, and can even work on upcoming days’ work too.
QUICK EXPLANATION
- Total hours of work at home required are (A_1+A_2+A_3+A_4+A_5)*P
- Total hours available before the weekend are 24*5 = 120
- If the required hours are strictly greater than available hours, Chef will have to work on weekends.
EXPLANATION
All we need to find here is the number of hours of work required to be completed at home, and the number of hours available.
The total hours available is easy, 24 hours a day for 5 days imply 120 hours.
The total hours of work required at home is P times total hours of work required at the office.
Hence, we have Total hours of work required at home as P* (A_1+A_2+A_3+A_4+A_5)
So, if we have P* (A_1+A_2+A_3+A_4+A_5) > 120, Chef will have to work on weekends too.
Bonus: Solve the same problem, assuming Chef cannot work on upcoming days’ work earlier.
TIME COMPLEXITY
The time complexity is O(1) per test case.
SOLUTIONS:
Setter's Solution
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll t;
cin>>t;
while(t--)
{
ll a[5],p;
ll sum = 0;
for(ll i=0;i<5;i++)
{
cin>>a[i];
sum += a[i];
}
cin>>p;
if(sum*p > 24*5)
cout<<"Yes\n";
else
cout<<"No\n";
}
return 0;
}
Tester's Solution
#include <bits/stdc++.h>
#define endl '\n'
#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
using namespace std;
template<class T, class T1> int chkmin(T &x, const T1 &y) { return x > y ? x = y, 1 : 0; }
template<class T, class T1> int chkmax(T &x, const T1 &y) { return x < y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);
int a[5], p;
void read() {
cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> p;
}
void solve() {
int sum = 0;
for(int i = 0; i < 5; i++) {
sum += p * a[i];
}
sum -= 24 * 5;
if(sum > 0) cout << "Yes" << endl;
else cout << "No" << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while(T--) {
read();
solve();
}
return 0;
}
Editorialist's Solution
import java.util.*;
import java.io.*;
import java.text.*;
class LOSTWKND{
//SOLUTION BEGIN
void pre() throws Exception{}
void solve(int TC) throws Exception{
int T = 0;
for(int i = 0; i< 5; i++)T += ni();
T *= ni();
if(T > 120)pn("Yes");
else pn("No");
}
//SOLUTION END
void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
DecimalFormat df = new DecimalFormat("0.00000000000");
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 LOSTWKND().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.