-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_46.cpp
115 lines (83 loc) · 2.21 KB
/
day_46.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
Name - himanshu Pokheiyal
Date - 10 May, 2024
Version - C++17
Ques-1
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/FILLCANDIES?tab=solution
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int n,k,m;
cin>>n>>k>>m;
if( n<(k*m)) cout<<"1"<<endl;
else{
if(n%(k*m) == 0) cout<<(n/(k*m))<<endl;
else if(n%(k*m)>0) cout<<(n/(k*m))+1<<endl;
}
}
}
Ques-2 Water Mixing
Link- https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/WTRMIXING
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int a,b,x,y;
cin>>a>>b>>x>>y;
if(a>b){
int req_value=a-b;
if(req_value>y){
cout<<"No"<<endl;
}
else cout<<"Yes"<<endl;
}
else if(a<b){
int req_value=b-a;
if(req_value>x) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
else cout<<"Yes"<<endl;
}
}
Time complexity - O(t)
Space complexity -- O(1)
# Slight optimisation
#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, x, y;
cin >> a >> b >> x >> y;
int temp_diff = abs(a - b); // Absolute difference in temperatures
// Check if the temperature difference can be achieved with available water
cout << ((temp_diff <= x + y && temp_diff % 2 == (x + y) % 2) ? "Yes" : "No") << endl;
}
return 0;
}
Ques-3 Weights
Link - https://www.codechef.com/practice/course/logical-problems/DIFF800/problems/WGHTS
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while( t-- ){
int w,x,y,z;
cin>>w>>x>>y>>z;
if( w == x || w== y || w==z || w == ( x+y) || w== (y+z) || w== (x+z) || w== (x+y+z) ) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
Time complexity - O(t)
Space complexity - O(1)
*/