LOSTWKND - Editorial

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. :slight_smile:

#include <bits/stdc++.h>
#define vi vector<int>
#define pi pair<int, int>
#define vs vector<string>
#define mp make_pair
#define mi map<int, int>
#define ull unsigned long long int
#define fo(i, k, n) for(int i = k; i < n; i++)
#define pqi priority_queue<int>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define INF 1e18
#define f first
#define s second

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		int p;
		int sum;
		for(int i = 0; i < 5; i++){
            int a1;
            cin >> a1;
            sum += a1;
		}
		cin >> p;
		int hours = sum*p;
		if(hours > 120) cout << "Yes" << "\n";
		else cout << "No" << "\n";
	}
	return 0;
}

@taran_1407 @hackslash_123 @galencolin can you please tell me why this code is showing WA??
I have done basically the same thing as explained in the editorial.

Initialize sum

You haven’t initialized sum to zero.

it passed the sample cases…

on your computer?

i initialized the sum and it worked but i still dont get how the code passed the sample cases

A silly mistake can turn into a big blunders.

Did it pass samples on CodeChef IDE or just your computer? Either way, it’s probably the multitests causing sum to have some garbage value.

on my computer as well as on ideone…
probably were the multitests

what about CodeChef IDE

thanks got it. it was the multitests causing it to go haywire

import java.io.;
import java.lang.
;
import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int t,p;
t=in.nextInt();
for(int i=t;i>0;i–)
{
int a[]=new int[5];
for(int j=0;j<5;j++)
{
a[j]=in.nextInt();
}
p=in.nextInt();
long sum=0,s=0;
for(int j=0;j<5;j++)
{
sum=sum+a[j];
}
if((sum*p) > 120)
System.out.println(“YES”);
else
System.out.println(“NO”);
}
}
}

same method still getting WA

Output may be case-sensitive

Also format your code

t=int(input())
for f in range(t):
l=[int(x) for x in input().split()]
sums=0
for i in range(5):
sums+=l[i]
sums=sums*l[5]
if(sums>144):
print(“YES”)
else:
print(“NO”)

Pls someone tell why this is not working

t=int(input())

for f in range(t):
l=[int(x) for x in input().split()]
sums=0
for i in range(5):
sums+=l[i]
sums=sums*l[5]
if(sums>144):
print(“YES”)
else:
print(“NO”)

Firstly, a workweek here is 5 days. So sum need to be greater than 120 only rather than 144.
Secondly, the output might be case sensitive.

@admin @everyone
I have done a similar approach and compared maximum work that can be done per day * 5 versus sum.
Why was this a WA as I have just transferred { Editorial : p * sum > 120 } to { sum > ( 120 / p ) }

Full code can be found here : CodeChef: Practical coding for everyone
int main()
{
tc
{
lli a[5] = {0}, p = 1;
aip(a, 5);
lli sum = 0;
rep(i, 0, 5)
sum += a[i];
cin >> p;
lli max = (24 / p) * 5;

	if (max >= sum)
		cout << "No\n";
	else
		cout << "Yes\n";
}
return 0;

}

By dividing the no of available hours from each day with p, you are discarding the fractional value which might affect the answer.

Sample test run but still getting WA

public static void main(String[] args) throws java.lang.Exception {
	List<Integer> numbers = new ArrayList<>(5);
	Scanner sc = new Scanner(System.in);

	IntStream.range(0, 5).forEach(x -> { 
		numbers.add(x, sc.nextInt()); 
	});	

	List<Integer> totalWorkingHours = new ArrayList<>();

	int pHour = sc.nextInt();

	numbers.forEach(workHour -> {
		int totalHourPerDay = workHour*pHour;
		totalWorkingHours.add(totalHourPerDay);
	});

	if (new Codechef().sumOfWeekdayHours(totalWorkingHours) <= 120) {
		System.out.println("No");
	} else {
		System.out.println("Yes");
	}
}
public int sumOfWeekdayHours(List<Integer> totalWorkingHours) {
	int sum = 0; 
	for (int weekdayHour : totalWorkingHours) {
		sum = sum + weekdayHour;
	}
	return sum;
}