#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], b[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
for (int i = 1; i <= m; i ++ ) cin >> b[i];
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
int ans = a[n];
if (n != 1) {
for (int i = 1; i <= m; i ++ )
if (b[i] > 0) ans += b[i];
} else {
for (int i = 1; i <= m; i ++ )
ans += b[i];
}
cout << ans << endl;
return 0;
}
B
#include <bits/stdc++.h>
using namespace std;
bool ok;
string g[25] = {"H","HE","LI","BE","B","C","N","O","F","NE",
"NA","MG","AL","SI","P","S","CL","AR","K","CA"};
string str;
void dfs(int dep) {
if (dep == str.size()) {
ok = 1;
return;
}
if (dep != str.size() - 1) {
string res = str.substr(dep, 2);
for (int j = 0; j < 20; j ++ )
if (g[j] == res) {
dfs(dep + 2);
break;
}
}
string res = str.substr(dep, 1);
for (int j = 0; j < 20; j ++ )
if (g[j] == res) {
dfs(dep + 1);
break;
}
}
int main() {
cin >> str;
dfs(0);
if (ok) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
C
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t -- ) {
int n;
cin >> n;
if (n & 1) cout << "potassium" << endl;
else cout <<"qxforever" << endl;
}
return 0;
}
D
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t -- ) {
int n;
cin >> n;
if (n == 4) {
cout << "2 0 2 0\n";
} else if (n == 5) {
cout << "2 1 2 0 0\n";
} else if (n > 6) {
cout << n - 4 << ' ';
cout << "2 1 ";
for (int i = 1; i <= n - 3; i ++ )
if (i + 2 == n - 4) cout << 1 << ' ' ;
else cout << 0 << " ";
cout << endl;
} else cout << -1 << endl;
}
return 0;
}
E
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 998244353;
const int N = 5e5 + 10;
const int base = 131;
long long ss[N], tt[N], fac[N];
char s[N], t[N];
void init() {
fac[0] = 1;
for (int i = 1; i < N; i ++ ) {
fac[i] = fac[i - 1] * base % mod;
}
}
bool check(int l, int r) {
if ((tt[r] - tt[l - 1] * fac[r - l + 1] % mod + mod) % mod == ss[r - l + 1])
return 1;
else return 0;
}
int main() {
int T;
scanf("%d", &T);
init();
while (T -- ) {
bool ok = 1;
scanf("%s", s + 1);
scanf("%s", t + 1);
int lens = strlen(s + 1), lent = strlen(t + 1);
for (int i = 1; i <= lens; i ++ )
ss[i] = (ss[i - 1] * base % mod + (s[i] - 'a' + 1)) % mod;
for (int i = 1; i <= lent; i ++ )
tt[i] = (tt[i - 1] * base % mod + (t[i] - 'a' + 1)) % mod;
for (int i = lent; i > 0; ) {
int j;
for (j = i; j > 0; j -- ) {
if (check(j, i)) {
break;
}
}
if (!j) {
ok = 0;
break;
}
i = j - 1;
}
if (ok) printf("Yes\n");
else printf("No\n");
}
return 0;
}
F
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= 2 * n; i ++ ) cin >> a[i];
int ans = 0;
for (int i = 1; i <= 2 * n; i += 2) {
if (a[i] > a[i + 1]) {
ans ++;
if (i + 3 <= 2 * n) {
if (a[i + 2] > a[i + 3] && a[i + 1] < a[i + 2] && a[i + 2] >= a[i]) {
swap(a[i + 1], a[i + 2]);
}
}
}
}
cout << ans << endl;
return 0;
}
The 16-th Beihang University Collegiate Programming
Link有空就写题解A#include <bits/stdc++.h>using namespace std;const int N = 1e5 + 10;int a[N], b[N];int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i ++ ) cin >> a[i]; for (int i = 1; i <= m; i ++