From acd87feea037aec1ec3017eab7d9b82b3fad60e0 Mon Sep 17 00:00:00 2001 From: vhaegar2615 <53910913+vhaegar1526@users.noreply.github.com> Date: Sat, 30 May 2020 22:19:01 +0530 Subject: [PATCH] Solved Codechef MayLunchtime Rated Contest 30thMay/2020 --- 10 Days of Statistics.cpp | 62 ------------------- .../Lost weekends (Ques)/Question.txt | 32 ++++++++++ .../Solution/Q1.cpp | 25 ++++++++ .../Solution/Q2.cpp | 41 ++++++++++++ .../Weird Walk (Ques)/Weird Walk.txt | 51 +++++++++++++++ 5 files changed, 149 insertions(+), 62 deletions(-) delete mode 100644 10 Days of Statistics.cpp create mode 100644 Codechef- MayLunchtimeQ1_(Rated Contest)/Lost weekends (Ques)/Question.txt create mode 100644 Codechef- MayLunchtimeQ1_(Rated Contest)/Solution/Q1.cpp create mode 100644 Codechef_MayLunchtimeQ2_(Rated Contest)/Solution/Q2.cpp create mode 100644 Codechef_MayLunchtimeQ2_(Rated Contest)/Weird Walk (Ques)/Weird Walk.txt diff --git a/10 Days of Statistics.cpp b/10 Days of Statistics.cpp deleted file mode 100644 index 4580312..0000000 --- a/10 Days of Statistics.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include - -using namespace std; -typedef unsigned long long int ll; - -int main() -{ - ll n,sum=0; cin >> n; - vector arr(n); - map freq; - - ll mode,max_freq=0; - for(ll i=0; i> arr[i]; - - if(freq.count(arr[i])) - freq[arr[i]]=1; - else - freq[arr[i]]++; - - if(freq[arr[i]]>max_freq){ - max_freq = freq[arr[i]]; - mode = arr[i]; - } - else if(freq[arr[i]]==max_freq && mode>arr[i]) - mode = arr[i]; - - sum+=arr[i]; - } - float mean = (float)sum/n; - mean = round(mean*10)/10; - - sort(arr.begin(), arr.end()); - float median; - if(n%2) - { - median = arr[(n/2)]; - } - else - median = (float)(arr[(n/2)-1]+arr[n/2])/2; - median = round(median*10)/10; - - -// map::iterator itr; -// for(itr=freq.begin(); itr!=freq.end(); itr++) -// { -//// cout << itr->first << " "<second << endl; -// if(itr->second > max_freq){ -// mode = itr->first; -// max_freq = itr->second; -// } -// if(itr->second == max_freq && itr->firstfirst; -//// cout << '*' << mode; -// } -// } - - printf("%.1f\n%.1f\n%d\n", mean, median, mode); - - return 0; -} diff --git a/Codechef- MayLunchtimeQ1_(Rated Contest)/Lost weekends (Ques)/Question.txt b/Codechef- MayLunchtimeQ1_(Rated Contest)/Lost weekends (Ques)/Question.txt new file mode 100644 index 0000000..561bd14 --- /dev/null +++ b/Codechef- MayLunchtimeQ1_(Rated Contest)/Lost weekends (Ques)/Question.txt @@ -0,0 +1,32 @@ +Chef recently started working at ABC corporation. Let's number weekdays (Monday through Friday) by integers 1 through 5. For each valid i, the number of hours Chef spent working at the office on weekday i was Ai. + +Unfortunately, due to the COVID-19 pandemic, Chef started working from home and his productivity decreased by a considerable amount. As per Chef's analysis, 1 hour of work done at the office is equivalent to P hours of work done at home. + +Now, in order to complete his work properly, Chef has to spend more hours working from home, possibly at the cost of other things like sleep. However, he does not have to do the same work on each day as he would have in the office ? for each weekday, he can start the work for this day on an earlier day and/or complete it on a later day. The only requirement is that his work does not pile up indefinitely, i.e. he can complete his work for each week during the same week. One day has 24 hours. + +If Chef is unable to complete his work for a week during those five weekdays, then he has to work during the weekend too. Chef wishes to know whether he has to work on weekends or if he can complete his work by working only on weekdays. Help him answer that question. (It is possible that Chef would be unable to finish his work even if he worked all the time, but he does not want to know about that.) + +Input +The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. +The first and only line of each test case contains six space-separated integers A1, A2, A3, A4, A5 and P. +Output +For each test case, print a single line containing the string "Yes" if Chef has to work on weekends or "No" otherwise (without quotes). + +Constraints +1=T=1,000 +0=Ai=24 for each valid i +1=P=24 +Subtasks +Subtask #1 (100 points): original constraints + +Example Input +2 +14 10 12 6 18 2 +10 10 10 10 10 3 +Example Output +No +Yes +Explanation +Example case 1: Here, P=2, so the number of hours Chef has to work from home to handle his workload for days 1 through 5 is [28,20,24,12,36]. If he works for full 24 hours on each of the five weekdays, he finishes all the work, so he does not have to work on weekends. + +Example case 2: No matter what Chef does, he will have to work on weekends. \ No newline at end of file diff --git a/Codechef- MayLunchtimeQ1_(Rated Contest)/Solution/Q1.cpp b/Codechef- MayLunchtimeQ1_(Rated Contest)/Solution/Q1.cpp new file mode 100644 index 0000000..bc7c171 --- /dev/null +++ b/Codechef- MayLunchtimeQ1_(Rated Contest)/Solution/Q1.cpp @@ -0,0 +1,25 @@ +#include + +using namespace std; + +bool solve(){ + int temp,p, sum=0; + for(int i=0; i<5; i++){ + cin >> temp; + sum+=temp; + } + cin >> p; + return sum*p>120; +} + +int main() +{ + int t; cin >> t; + while(t--) { + if(solve()) + cout << "Yes\n"; + else + cout << "No\n"; + } + return 0; +} diff --git a/Codechef_MayLunchtimeQ2_(Rated Contest)/Solution/Q2.cpp b/Codechef_MayLunchtimeQ2_(Rated Contest)/Solution/Q2.cpp new file mode 100644 index 0000000..b1c0671 --- /dev/null +++ b/Codechef_MayLunchtimeQ2_(Rated Contest)/Solution/Q2.cpp @@ -0,0 +1,41 @@ +#include + +using namespace std; + +typedef vector vect_i; +long solve(){ + int n; cin >> n; + vect_i a(n), b(n); + + int sumA=0,sumB=0; + + for(int i=0; i> a[i]; + } + + for(int i=0; i> b[i]; + } + + long weird_dist = (a[0]==b[0])?a[0]:0; + sumA=a[0]; sumB=b[0]; + for(int i=1; i> t; + while(t--) { + cout << solve() << endl; + } + return 0; +} diff --git a/Codechef_MayLunchtimeQ2_(Rated Contest)/Weird Walk (Ques)/Weird Walk.txt b/Codechef_MayLunchtimeQ2_(Rated Contest)/Weird Walk (Ques)/Weird Walk.txt new file mode 100644 index 0000000..9162229 --- /dev/null +++ b/Codechef_MayLunchtimeQ2_(Rated Contest)/Weird Walk (Ques)/Weird Walk.txt @@ -0,0 +1,51 @@ +Alice and Bob are walking on an infinite straight street. Initially, both are at the position X=0 and they start walking in the direction of increasing X. After N seconds, they stop. Let's denote Alice's speed and Bob's speed during the i-th of these seconds by Ai and Bi respectively. + +Sometimes, Alice and Bob walk together, i.e. with the same speed side by side. Let's define the weird distance as the total distance they walk this way. Find this weird distance. + +Input +The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. +The first line of each test case contains a single integer N. +The second line contains N space-separated integers A1,A2,…,AN. +The third line contains N space-separated integers B1,B2,…,BN. +Output +For each test case, print a single line containing one integer ? the total weird distance. It can be proved that this distance is an integer. + +Constraints +1=T=20 +1=N=105 +1=Ai=105 for each valid i +1=Bi=105 for each valid i +the sum of N over all test cases does not exceed 106 +Subtasks +Subtask #1 (30 points): 1=N=1,000 +Subtask #2 (70 points): original constraints + +Example Input +3 +4 +1 3 3 4 +1 2 4 4 +2 +2 3 +3 2 +2 +3 3 +3 3 +Example Output +5 +0 +6 +Explanation +Example case 1: + +Alice and Bob walk side by side during the first second, from X=0 to X=1. +Then, Alice starts walking faster than Bob, so they do not walk side by side during second 2. At the end of second 2, Alice is at X=4, while Bob is at X=3. +During the next second, they again do not walk side by side, but Bob walks faster, so they both end up at X=7. +During the last second, they both walk side by side and the distance they walk is 4. +Alice and Bob walk side by side during the 1-st and 4-th second and the total weird distance they travel is 1+4=5. +Example case 2: + +First, Alice walks with speed 2 and Bob walks with speed 3, so they do not walk side by side. Alice ends up at X=2, while Bob ends up at X=3 at the end of the 1-st second. +Then, Alice walks with speed 3 and Bob walks with speed 2, so they do not walk side by side either. +Although Alice and Bob both end up at X=5 at the end of the 2-nd second, the weird distance is 0. +Example case 3: We can see that Alice and Bob always walk together, so the weird distance is 3+3=6. \ No newline at end of file