new problems

This commit is contained in:
2026-09-25 22:31:50 +01:00
parent fe0b8be533
commit 440d51caba
26 changed files with 1186 additions and 1 deletions
View File
+115
View File
@@ -0,0 +1,115 @@
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
takeI(t);
while (t--) {
takeI(n);
takeS(s);
// If prefix is 1, then only option is to convert all zeros to ones
int numZeros = 0;
for (auto x : s) if (x == '0') numZeros++;
if (s[0] == '1') {
cout << numZeros << '\n';
continue;
}
// Skip leading 0s
// Index i is at position of first 1
int seenZeros = 0, seenOnes = 0;
int i = 0; while (i < n && s[i] == '0') {seenZeros++; i++;}
// Cost to flip remaining 0s to 1s
int min_cost = numZeros - seenZeros;
for (int j = i; j < n; j++) {
if (s[j] == '1') seenOnes++;
else seenZeros++;
int curr_cost = (numZeros - seenZeros) + seenOnes;
min_cost = min(min_cost, curr_cost);
}
cout << min_cost << '\n';
}
}
+13
View File
@@ -0,0 +1,13 @@
6
4
0011
4
1000
5
01000
8
01001101
7
0101010
7
0111101
+102
View File
@@ -0,0 +1,102 @@
#include <map>
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
takeI(t);
while (t--) {
takeII(n, m);
takeV(b, m);
// The last occurance of bi is at i
for (int i = 0; i < m; i++)
if (i <= n)
lastIndex[b[i]] = i;
if (lastIndex.size() != n) {
cout << -1 << '\n';
continue;
}
for (auto [k, v] : lastIndex) cout << k << ' ' << v << '\n';
cout << 1 << '\n';
}
}
+1
View File
@@ -0,0 +1 @@
https://codeforces.com/problemset/problem/2264/D
+90
View File
@@ -0,0 +1,90 @@
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
takeI(t);
while (t--) {
takeI(n);
// 1010101
}
}
+96
View File
@@ -0,0 +1,96 @@
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
takeI(t);
while (t--) {
takeI(n);
takeV(a, n);
int res = 0;
// can move a[j] to a[i]
// [ai, ai+1, ai+2 ... aj]
// [aj - (j - i), ai+1, ai+2, ... aj-1 + 1]
cout << res << '\n';
}
}
+94
View File
@@ -0,0 +1,94 @@
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
takeI(t);
while (t--) {
takeI(n);
takeIII(a1,a2,a3);
int res = 0;
res = max({n-a1, n-a2, n-a3});
cout << res << '\n';
}
}
@@ -0,0 +1,99 @@
#include <bits/stdc++.h>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
#define SP " "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
takeI(t);
while (t--) {
takeII(n, k);
takeS(s);
int redTeamScore = 0, blueTeamScore = 0;
// Initially, some s[i] = 1
// The game then lasts for k rounds.
//
// For all s[i] == 1
// Keep s[i] == 1 or if (s[i+1 % (2n)] == 0) then s[i+1 % (2n)] = 1
// Find the scores of the Red Team and the Blue Team if both teams play optimally. It can be shown that the scores under optimal play are uniquely determined.
cout << redTeamScore << SP << blueTeamScore << NL;
}
}
+112
View File
@@ -0,0 +1,112 @@
#include <map>
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
takeI(t);
while (t--) {
takeII(n, k);
takeV(a, n);
// We don't care if x <= k
map<int, int> multiset;
for (auto x : a) if (x > k) multiset[x]++;
// Multiset contains all 'naughty elements'
// Fastest idea is to remove largest prime factor of x
//
int fk;
// Choose an integer x>1 from the multiset
// Choose prime divisor p of x.
//
// Then
//
// Remove one occurrence of x from the multiset
// add p copies of x / p.
// Let f(k) be the minimum number of operations required
// starting from the original multiset
// until every integer in the multiset is at most k.
cout << fk << '\n';
}
}
+1
View File
@@ -0,0 +1 @@
https://codeforces.com/contest/2184/problem/A
+114
View File
@@ -0,0 +1,114 @@
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
takeI(t);
while (t--) {
takeI(n);
int res;
/**
Keep putting 3, 3 in each civ
We will be left with n % 6
Keep putting 2, 2 in each civ
We are left with n % 4
2 -> 2
3 -> 3
4 -> 0
5 -> 1
6 -> 0
7 -> 1
8 -> 0
9 -> 1
10 -> 0
11 -> 1
12 -> 0
* */
cout << res << NL;
}
}
@@ -0,0 +1,101 @@
#include <bits/stdc++.h>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
#define SP " "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int maxDiff(int a, int b, int c) {
return max({abs(a-b), abs(a-c), abs(b-c)});
}
int main() {
FASTIO;
takeI(t);
while (t--) {
takeIII(a,b,c);
int rng = min({maxDiff(a,b,c), maxDiff(a,b,a+b), maxDiff(a,a+c,c), maxDiff(b+c, b,c)});
// Choose one of the three current integers and replace it with the sum of the other two current integers. The other two integers remain unchanged.
// Do this any number of times
// Find minumum range of integers
// (a,b,c) -> (b+c, b, c)
cout << rng << NL;
}
}
+94
View File
@@ -0,0 +1,94 @@
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
takeI(t);
while (t--) {
long long a, b, c;
cin >> a >> b >> c;
long long res = 0;
res = max(abs(a-b), abs(a+c) - b);
cout << res << '\n';
}
}
View File