Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
- #define X first
- #define Y second
- #define Push push_back
- #define ALL(x) x.begin(), x.end()
- using lli = long long;
- using pll = pair<lli, lli>;
- using Double = long double;
- template<typename T>
- using Vector = vector<vector<T>>;
- template<typename T>
- using prior = priority_queue<T>;
- bool cmp(pair<string, int> a, pair<string, int> b) {
- if (a.Y == b.Y) return a.X < b.X;
- return a.Y > b.Y;
- }
- int main() {
- IOS;
- int n, m, p;
- cin >> n >> m;
- vector<pair<string, int>> vs(n, {"", 0});
- for (auto &x : vs) cin >> x.X;
- cin >> p;
- string vote;
- while (p--) {
- cin >> vote;
- if (vote.size() != n) continue;
- bool flag = false;
- int cnt = 0;
- for (auto x : vote) {
- if (x == '0'); // good
- else if (x == '*') {
- if (++cnt > m) break;
- }
- else {
- flag = true;
- break;
- }
- }
- if (flag or cnt > m) continue;
- for (int i = 0; i < n; ++i) {
- vs[i].Y += (vote[i] == '*');
- }
- }
- sort(ALL(vs), cmp);
- for (auto x : vs) cout << x.X << ' ' << x.Y << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement