-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1931E Anna and the Valentine_s Day Gift.cpp
57 lines (52 loc) · 1.32 KB
/
1931E Anna and the Valentine_s Day Gift.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
/*
author : MishkatIT
created : Wednesday 2024-02-14-00.47.16
*/
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(_) cout << #_ << " is " << _ << '\n';
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 10;
const ll inf = 1e9;
const ll linf = 1e18;
int main()
{
fio;
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<int> v(n);
for (auto& i : v) cin >> i;
vector<pair<int, string>> z;
for (int i = 0; i < n; i++) {
string x = to_string(v[i]);
int zero = 0;
while(x.back() == '0') {
zero++;
x.pop_back();
}
z.push_back({zero, x});
}
sort(z.begin(), z.end());
string temp = "";
bool ok = true;
for (int i = z.size() - 1; i >= 0; i -= 2) {
temp += z[i].second;
if (i > 0) {
temp += z[i - 1].second;
temp += string(z[i - 1].first, '0');
}
if (temp.size() > m) {
ok = false;
break;
}
}
cout << (ok ? "Anna" : "Sasha") << '\n';
}
return 0;
}