-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from Coach-Academy/MohamedAmir-patch1
c102 Practice G2 Week 10
- Loading branch information
Showing
12 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/A - Electronics Shop.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int b, n, m; | ||
cin >> b >> n >> m; | ||
vector<int> keyboards(n), usbs(m); | ||
for (auto &in: keyboards) | ||
cin >> in; | ||
for (auto &in: usbs) | ||
cin >> in; | ||
|
||
int ans = -1; | ||
|
||
for (auto &keyboard: keyboards) { | ||
for (auto &usb: usbs) { | ||
if (usb + keyboard <= b) { | ||
ans = max(ans, usb + keyboard); | ||
} | ||
} | ||
} | ||
cout << ans << endl; | ||
} |
18 changes: 18 additions & 0 deletions
18
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/B - Compare the Triplets.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int alice = 0, bob = 0; | ||
vector<pair<int, int>> scores(3); | ||
for (auto &v: scores) | ||
cin >> v.first; | ||
for (auto &v: scores) | ||
cin >> v.second; | ||
|
||
for (int i = 0; i < 3; ++i) { | ||
alice += scores[i].first > scores[i].second; | ||
bob += scores[i].first < scores[i].second; | ||
} | ||
cout << alice << ' ' << bob << endl; | ||
} |
16 changes: 16 additions & 0 deletions
16
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/C - Slot.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
set<char> st; | ||
for (int i = 0; i < 3; ++i) { | ||
char ch; | ||
cin >> ch; | ||
st.insert(ch); | ||
} | ||
if (st.size() == 1) | ||
cout << "Won\n"; | ||
else | ||
cout << "Lost\n"; | ||
} |
27 changes: 27 additions & 0 deletions
27
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/D - Dragons.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int s, n; | ||
cin >> s >> n; | ||
multiset<pair<int, int>> dragons; | ||
for (int i = 0; i < n; ++i) { | ||
int x, y; | ||
cin >> x >> y; | ||
dragons.insert({x, y}); | ||
} | ||
bool ans = 1; | ||
for (auto &dragon: dragons) { | ||
if (s > dragon.first) | ||
s += dragon.second; | ||
else | ||
ans = false; | ||
} | ||
if (ans) | ||
cout << "YES\n"; | ||
else | ||
cout << "NO\n"; | ||
|
||
|
||
} |
17 changes: 17 additions & 0 deletions
17
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/E - Currency System in Geraldion.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int n; | ||
cin >> n; | ||
for (int i = 0; i < n; ++i) { | ||
int s; | ||
cin >> s; | ||
if (s == 1) { | ||
cout << -1 << endl; | ||
return 0; | ||
} | ||
} | ||
cout << 1 << endl; | ||
} |
18 changes: 18 additions & 0 deletions
18
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/F - Partition.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int n; | ||
cin >> n; | ||
int pos = 0, neg = 0; | ||
for (int i = 0; i < n; ++i) { | ||
int s; | ||
cin >> s; | ||
if (s > 0) | ||
pos += s; | ||
else | ||
neg += s; | ||
} | ||
cout << pos - neg << endl; | ||
} |
18 changes: 18 additions & 0 deletions
18
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/G - Puzzles.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int m, n; | ||
cin >> m >> n; | ||
vector<int> v(n); | ||
for (int i = 0; i < n; ++i) { | ||
cin >> v[i]; | ||
} | ||
sort(v.begin(), v.end()); | ||
int mn = INT_MAX; | ||
for (int i = 0; i + m - 1 < n; ++i) { | ||
mn = min(mn, v[i + m - 1] - v[i]); | ||
} | ||
cout << mn << endl; | ||
} |
16 changes: 16 additions & 0 deletions
16
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/H - Difference Row.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int n; | ||
cin >> n; | ||
vector<int> v(n); | ||
for (int i = 0; i < v.size(); ++i) { | ||
cin >> v[i]; | ||
} | ||
sort(v.begin(), v.end()); | ||
swap(v.front(), v.back()); | ||
for (auto &s: v) | ||
cout << s << ' '; | ||
} |
25 changes: 25 additions & 0 deletions
25
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/I - Tit for Tat.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
while (t--) { | ||
int n, k; | ||
cin >> n >> k; | ||
vector<int> v(n); | ||
for (int i = 0; i < n; ++i) { | ||
cin >> v[i]; | ||
} | ||
for (int i = 0; i < n - 1 and k;) { | ||
if (v[i] - 1 >= 0) | ||
v[i]--, v.back()++, k--; | ||
else | ||
i++; | ||
} | ||
for (auto &s: v) | ||
cout << s << ' '; | ||
cout << endl; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/J - Little Elephant and Bits.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
string s; | ||
cin >> s; | ||
if (s.find('0') != string::npos) | ||
s.erase(s.begin() + s.find('0')); | ||
else | ||
s.pop_back(); | ||
cout << s << endl; | ||
} |
25 changes: 25 additions & 0 deletions
25
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/K - Dense Array.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
while (t--) { | ||
int n; | ||
cin >> n; | ||
vector<int> v(n); | ||
for (int i = 0; i < n; ++i) { | ||
cin >> v[i]; | ||
} | ||
int ans = 0; | ||
for (int i = 0; i < v.size() - 1; ++i) { | ||
int mn = min(v[i], v[i + 1]), mx = max(v[i], v[i + 1]); | ||
while (mn * 2 < mx) { | ||
ans++; | ||
mn *= 2; | ||
} | ||
} | ||
cout << ans << endl; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Level 1/CPU - Standard - L1 - C102/Practice G2/Week 10/L - Single Push.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
while (t--) { | ||
int n; | ||
cin >> n; | ||
deque<int> a(n), b(n); | ||
for (auto &s: a) | ||
cin >> s; | ||
for (auto &s: b) | ||
cin >> s; | ||
while (a.size() and a.front() == b.front()) | ||
b.pop_front(), a.pop_front(); | ||
while (a.size() and a.back() == b.back()) | ||
b.pop_back(), a.pop_back(); | ||
set<int> st; | ||
for (int i = 0; i < a.size(); ++i) { | ||
st.insert(b[i] - a[i]); | ||
} | ||
if ((st.size() == 1 and *st.begin() > 0)) | ||
cout << "YES\n"; | ||
else if (st.empty()) | ||
cout << "YES\n"; | ||
else | ||
cout << "NO\n"; | ||
} | ||
} |