Skip to content

Commit 0c8cd33

Browse files
Add files via upload
1 parent ef803ce commit 0c8cd33

File tree

5 files changed

+194
-0
lines changed

5 files changed

+194
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
for _ in range(int(input())):
2+
a, b, c = map(int, input().split())
3+
if (a + b + c) % 3 != 0:
4+
print("NO")
5+
continue
6+
7+
target = (a + b + c) // 3
8+
9+
if b > target:
10+
print("NO")
11+
continue
12+
13+
avail = c - target
14+
need = (target - a) + (target - b)
15+
if avail >= need:
16+
print("YES")
17+
else:
18+
print("NO")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
for _ in range(int(input())):
2+
n = int(input())
3+
arr = list(map(int, input().split()))
4+
5+
ans: list = []
6+
maxi = 0
7+
cur = sum(arr)
8+
for i in range(n):
9+
if maxi > arr[i]:
10+
ans.append(cur - arr[i] + maxi)
11+
else:
12+
ans.append(cur)
13+
14+
maxi = max(maxi, arr[i])
15+
cur -= arr[i]
16+
17+
print(*ans[::-1])

Other_Tasks/CF2104_C_Card_Game.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
for _ in range(int(input())):
2+
n = int(input())
3+
a: set[int] = set()
4+
b: set[int] = set()
5+
6+
x = list(input().strip())
7+
8+
for i in range(n):
9+
if x[i] == 'A':
10+
a.add(i+1)
11+
else:
12+
b.add(i+1)
13+
14+
if 1 in a and n in a:
15+
print("Alice")
16+
elif 1 in b and n in b:
17+
print("Bob")
18+
elif 1 in b and n in a and n-1 in b:
19+
print("Bob")
20+
elif 1 in b and n in a and n-1 in a:
21+
print("Alice")
22+
elif 1 in a and n in b and n-1 in b:
23+
print("Bob")
24+
25+
else:
26+
assert 1 in a and n in b and n-1 in a
27+
28+
if len(b) == 1:
29+
print("Alice")
30+
else:
31+
print("Bob")
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <numeric>
2+
#pragma GCC optimize("Ofast")
3+
#pragma GCC optimize("unroll-loops")
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
using ll = long long;
8+
using vi = vector<int>;
9+
#define fast_cin() \
10+
ios_base::sync_with_stdio(false); \
11+
cin.tie(NULL); \
12+
cout.tie(NULL);
13+
14+
typedef long long ll;
15+
typedef vector<ll> vll;
16+
17+
ll _sieve_size;
18+
bitset<10000010> bs;
19+
vll primes;
20+
21+
// Able to handle 1e7 in < 1s
22+
void sieve(ll upperbound = (ll)1e7) {
23+
_sieve_size = upperbound + 1;
24+
bs.set();
25+
bs[0] = bs[1] = 0;
26+
for (ll i = 2; i <= _sieve_size; i++) {
27+
if (bs[i]) {
28+
for (ll j = i * i; j <= _sieve_size; j += i) {
29+
bs[j] = 0;
30+
}
31+
primes.push_back(i);
32+
}
33+
}
34+
}
35+
36+
void solve() {
37+
int n;
38+
cin >> n;
39+
vector<ll> a(n);
40+
for (auto &x : a) cin >> x;
41+
sort(a.begin(), a.end());
42+
43+
ll required = accumulate(primes.begin(), primes.begin() + n, 0LL);
44+
ll have = accumulate(a.begin(), a.end(), 0LL);
45+
46+
for (int i = 0; i < n; i++) {
47+
if (have >= required) {
48+
cout << i << endl;
49+
return;
50+
}
51+
have -= a[i];
52+
required -= primes[n - 1 - i];
53+
}
54+
55+
cout << n - 1 << endl;
56+
return;
57+
}
58+
59+
int main() {
60+
sieve(1e7);
61+
int tc;
62+
cin >> tc;
63+
while (tc--) solve();
64+
65+
return 0;
66+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <algorithm>
2+
#pragma GCC optimize("Ofast")
3+
#pragma GCC optimize("unroll-loops")
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
using ll = long long;
8+
using vi = vector<int>;
9+
#define fast_cin() \
10+
ios_base::sync_with_stdio(false); \
11+
cin.tie(NULL); \
12+
cout.tie(NULL);
13+
14+
int n, k;
15+
int main() {
16+
cin >> n >> k;
17+
vector<int> a(n);
18+
for (auto &x : a) {
19+
char c;
20+
cin >> c;
21+
x = c - 'a';
22+
}
23+
24+
vector<int> dp(n + 1, -1);
25+
vector<int> nexts(k, n);
26+
dp[n] = 0;
27+
for (int i = n - 1; i >= 0; i--) {
28+
int idx =
29+
distance(nexts.begin(), max_element(nexts.begin(), nexts.end()));
30+
dp[i] = dp[nexts[idx]] + 1;
31+
nexts[a[i]] = i;
32+
}
33+
34+
vector<vector<int>> positions(k);
35+
for (int i = 0; i < n; i++) {
36+
positions[a[i]].push_back(i);
37+
}
38+
39+
int q;
40+
cin >> q;
41+
while (q--) {
42+
string s;
43+
cin >> s;
44+
45+
// We iterate through the string by jumping via positions
46+
int cur = -1;
47+
for (auto &c : s) {
48+
int char_idx = c - 'a';
49+
auto it = upper_bound(positions[char_idx].begin(),
50+
positions[char_idx].end(), cur);
51+
if (it == positions[char_idx].end()) {
52+
cur = n;
53+
} else {
54+
cur = *it;
55+
}
56+
}
57+
58+
cout << (dp[cur]) << endl;
59+
}
60+
61+
return 0;
62+
}

0 commit comments

Comments
 (0)