Skip to content

Commit c2ddf2d

Browse files
committed
Add solution for problem B - Mahmoud and Ehab and the message
Link: https://codeforces.com/contest/959/problem/B Tags: dsu, greedy, implementation, *1200 Ref: https://codeforces.com/contest/959/submission/268824307
1 parent b1f4fee commit c2ddf2d

File tree

3 files changed

+93
-15
lines changed

3 files changed

+93
-15
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@ A repository to keep track of problem solving practice, containing solutions fro
1313

1414
| # | Title | Solution | Tags | Submitted |
1515
|---| ----- | -------- | ---- | --------- |
16-
1511 | [D - Caesar's Legions](https://codeforces.com/contest/118/problem/D) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/118/118D%20Caesar_s%20Legions.cpp "C++20 (GCC 13-64)") | `dp` `*1700` | Jul/25/2024 02:48 |
17-
1510 | [A - Diverse Game](https://codeforces.com/contest/1994/problem/A) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1994/1994A%20Diverse%20Game.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `greedy` `implementation` | Jul/24/2024 13:55 |
18-
1509 | [B - Number Circle](https://codeforces.com/contest/1189/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1189/1189B%20Number%20Circle.cpp "C++20 (GCC 13-64)") | `greedy` `math` `sortings` `*1100` | Jul/16/2024 23:21 |
19-
1508 | [B - Make Majority](https://codeforces.com/contest/1988/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1988/1988B%20Make%20Majority.cpp "C++20 (GCC 13-64)") | `greedy` `implementation` `*900` | Jul/15/2024 21:59 |
20-
1507 | [B - The Best Gift](https://codeforces.com/contest/609/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/609/609B%20The%20Best%20Gift.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `implementation` `*1100` | Jul/14/2024 00:17 |
21-
1506 | [B - Dinner with Emma](https://codeforces.com/contest/616/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/616/616B%20Dinner%20with%20Emma.cpp "C++20 (GCC 13-64)") | `games` `greedy` `*1000` | Jul/13/2024 23:53 |
22-
1505 | [E - XOR on Segment](https://codeforces.com/contest/242/problem/E) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/242/242E%20XOR%20on%20Segment.cpp "C++20 (GCC 13-64)") | `bitmasks` `data structures` `*2000` | Jul/13/2024 00:15 |
23-
1504 | [D - Test of Love](https://codeforces.com/contest/1992/problem/D) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1992/1992D%20Test%20of%20Love.cpp "C++20 (GCC 13-64)") | `dp` `greedy` `implementation` `*1200` | Jul/12/2024 00:37 |
24-
1503 | [C - Gorilla and Permutation](https://codeforces.com/contest/1992/problem/C) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1992/1992C%20Gorilla%20and%20Permutation.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `math` `*900` | Jul/11/2024 21:37 |
25-
1502 | [A - Only Pluses](https://codeforces.com/contest/1992/problem/A) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1992/1992A%20Only%20Pluses.cpp "C++20 (GCC 13-64)") | `brute force` `constructive algorithms` `greedy` `math` `sortings` `*800` | Jul/11/2024 20:59 |
26-
1501 | [B - Angry Monk](https://codeforces.com/contest/1992/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1992/1992B%20Angry%20Monk.cpp "C++20 (GCC 13-64)") | `greedy` `math` `sortings` `*800` | Jul/11/2024 20:49 |
27-
1500 | [B - Corner Twist](https://codeforces.com/contest/1983/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1983/1983B%20Corner%20Twist.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `greedy` `implementation` `math` `*1200` | Jul/08/2024 01:26 |
28-
1499 | [A - Array Divisibility](https://codeforces.com/contest/1983/problem/A) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1983/1983A%20Array%20Divisibility.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `math` `*800` | Jul/08/2024 00:33 |
29-
1498 | [B - Interesting Subarray](https://codeforces.com/contest/1270/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1270/1270B%20Interesting%20Subarray.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `greedy` `math` `*1200` | Jul/07/2024 16:42 |
30-
1497 | [B - Assigning to Classes](https://codeforces.com/contest/1300/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1300/1300B%20Assigning%20to%20Classes.cpp "C++20 (GCC 13-64)") | `greedy` `implementation` `sortings` `*1000` | Jul/07/2024 16:29 |
16+
1512 | [D - Caesar's Legions](https://codeforces.com/contest/118/problem/D) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/118/118D%20Caesar_s%20Legions.cpp "C++20 (GCC 13-64)") | `dp` `*1700` | Jul/25/2024 02:48 |
17+
1511 | [A - Diverse Game](https://codeforces.com/contest/1994/problem/A) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1994/1994A%20Diverse%20Game.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `greedy` `implementation` | Jul/24/2024 13:55 |
18+
1510 | [B - Number Circle](https://codeforces.com/contest/1189/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1189/1189B%20Number%20Circle.cpp "C++20 (GCC 13-64)") | `greedy` `math` `sortings` `*1100` | Jul/16/2024 23:21 |
19+
1509 | [B - Make Majority](https://codeforces.com/contest/1988/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1988/1988B%20Make%20Majority.cpp "C++20 (GCC 13-64)") | `greedy` `implementation` `*900` | Jul/15/2024 21:59 |
20+
1508 | [B - The Best Gift](https://codeforces.com/contest/609/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/609/609B%20The%20Best%20Gift.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `implementation` `*1100` | Jul/14/2024 00:17 |
21+
1507 | [B - Dinner with Emma](https://codeforces.com/contest/616/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/616/616B%20Dinner%20with%20Emma.cpp "C++20 (GCC 13-64)") | `games` `greedy` `*1000` | Jul/13/2024 23:53 |
22+
1506 | [E - XOR on Segment](https://codeforces.com/contest/242/problem/E) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/242/242E%20XOR%20on%20Segment.cpp "C++20 (GCC 13-64)") | `bitmasks` `data structures` `*2000` | Jul/13/2024 00:15 |
23+
1505 | [D - Test of Love](https://codeforces.com/contest/1992/problem/D) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1992/1992D%20Test%20of%20Love.cpp "C++20 (GCC 13-64)") | `dp` `greedy` `implementation` `*1200` | Jul/12/2024 00:37 |
24+
1504 | [C - Gorilla and Permutation](https://codeforces.com/contest/1992/problem/C) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1992/1992C%20Gorilla%20and%20Permutation.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `math` `*900` | Jul/11/2024 21:37 |
25+
1503 | [A - Only Pluses](https://codeforces.com/contest/1992/problem/A) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1992/1992A%20Only%20Pluses.cpp "C++20 (GCC 13-64)") | `brute force` `constructive algorithms` `greedy` `math` `sortings` `*800` | Jul/11/2024 20:59 |
26+
1502 | [B - Angry Monk](https://codeforces.com/contest/1992/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1992/1992B%20Angry%20Monk.cpp "C++20 (GCC 13-64)") | `greedy` `math` `sortings` `*800` | Jul/11/2024 20:49 |
27+
1501 | [B - Corner Twist](https://codeforces.com/contest/1983/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1983/1983B%20Corner%20Twist.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `greedy` `implementation` `math` `*1200` | Jul/08/2024 01:26 |
28+
1500 | [A - Array Divisibility](https://codeforces.com/contest/1983/problem/A) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1983/1983A%20Array%20Divisibility.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `math` `*800` | Jul/08/2024 00:33 |
29+
1499 | [B - Interesting Subarray](https://codeforces.com/contest/1270/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1270/1270B%20Interesting%20Subarray.cpp "C++20 (GCC 13-64)") | `constructive algorithms` `greedy` `math` `*1200` | Jul/07/2024 16:42 |
30+
1498 | [B - Assigning to Classes](https://codeforces.com/contest/1300/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1300/1300B%20Assigning%20to%20Classes.cpp "C++20 (GCC 13-64)") | `greedy` `implementation` `sortings` `*1000` | Jul/07/2024 16:29 |
31+
1497 | [B - Mahmoud and Ehab and the message](https://codeforces.com/contest/959/problem/B) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/959/959B%20Mahmoud%20and%20Ehab%20and%20the%20message.cpp "C++20 (GCC 13-64)") | `dsu` `greedy` `implementation` `*1200` | Jul/05/2024 00:48 |
3132
1496 | [A - BowWow and the Timetable](https://codeforces.com/contest/1204/problem/A) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1204/1204A%20BowWow%20and%20the%20Timetable.cpp "C++20 (GCC 13-64)") | `math` `*1000` | Jul/03/2024 01:01 |
3233
1495 | [A - XXXXX](https://codeforces.com/contest/1364/problem/A) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1364/1364A%20XXXXX.cpp "C++20 (GCC 13-64)") | `brute force` `data structures` `number theory` `two pointers` `*1200` | Jul/03/2024 00:12 |
3334
1494 | [A - Ilya and a Colorful Walk](https://codeforces.com/contest/1119/problem/A) | [C++20 (GCC 13-64)](https://github.com/MishkatIT/codeforces-atcoder-submissions/blob/main/codeforces/1119/1119A%20Ilya%20and%20a%20Colorful%20Walk.cpp "C++20 (GCC 13-64)") | `greedy` `implementation` `*1100` | Jul/02/2024 23:44 |
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Author : MishkatIT
3+
Created : Friday 05-07-2024 00:34:31
4+
*/
5+
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
9+
#ifdef LOCAL
10+
#include "algo/debug.h"
11+
#else
12+
#define debug(...) 42
13+
#endif
14+
15+
using ll = long long;
16+
using ld = long double;
17+
const ll mod = 1e9 + 7;
18+
const ll N = 2e5 + 10;
19+
const ll inf = 1e9;
20+
const ll linf = 1e18;
21+
22+
int main() {
23+
ios_base::sync_with_stdio(false);
24+
cin.tie(NULL);
25+
26+
int n, k, m;
27+
cin >> n >> k >> m;
28+
vector<string> lan(n);
29+
for (auto& i : lan) cin >> i;
30+
vector<int> cost(n);
31+
for (auto& i : cost) cin >> i;
32+
for (int i = 0; i < k; i++) {
33+
int len;
34+
cin >> len;
35+
vector<int> temp(len);
36+
for (auto& val : temp) {
37+
cin >> val;
38+
}
39+
int mn = inf;
40+
for (auto& x : temp) {
41+
mn = min(mn, cost[x - 1]);
42+
}
43+
for (auto& x : temp) {
44+
cost[x - 1] = mn;
45+
}
46+
}
47+
map<string, int> mp;
48+
for (int i = 0; i < n; i++) {
49+
mp[lan[i]] = cost[i];
50+
}
51+
ll ans = 0;
52+
for (int i = 0; i < m; i++) {
53+
string x;
54+
cin >> x;
55+
ans += mp[x];
56+
}
57+
cout << ans << '\n';
58+
return 0;
59+
}

submissions.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29817,6 +29817,24 @@
2981729817
],
2981829818
"timestamp": "Jul/03/2024 01:01"
2981929819
},
29820+
"CF268824307": {
29821+
"contest_id": 959,
29822+
"language": "C++20 (GCC 13-64)",
29823+
"path": "codeforces\\959\\959B Mahmoud and Ehab and the message.cpp",
29824+
"platform": "Codeforces",
29825+
"problem_index": "B",
29826+
"problem_name": "Mahmoud and Ehab and the message",
29827+
"problem_url": "https://codeforces.com/contest/959/problem/B",
29828+
"submission_id": "CF268824307",
29829+
"submission_url": "https://codeforces.com/contest/959/submission/268824307",
29830+
"tags": [
29831+
"dsu",
29832+
"greedy",
29833+
"implementation",
29834+
"*1200"
29835+
],
29836+
"timestamp": "Jul/05/2024 00:48"
29837+
},
2982029838
"CF269195049": {
2982129839
"contest_id": 1300,
2982229840
"language": "C++20 (GCC 13-64)",

0 commit comments

Comments
 (0)