solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
string x, y;
char temp;
cin >> x >> y;
sort(y.begin(), y.end(), greater<int>());
for (int i = 0, j = 0; i < y.length() && j < x.length(); i++, j++) {
if (y[i] > x[j]) {
temp = y[i];
y[i] = x[j];
x[j] = temp;
} else
i--;... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> cnt, mark;
long long dp[35][35];
long long func(long long n, long long r) {
if ((n == r) || (r == 0)) return 1;
if (dp[n][r] != -1) return dp[n][r];
return dp[n][r] = func(n - 1, r - 1) + func(n - 1, r);
}
int main() {
long long i, j, k, l,... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, s, k;
vector<vector<int> > graph(100001);
int ans[100001][101];
int vis[100001];
vector<vector<int> > knode(101);
void build_ans() {
int i, j;
queue<pair<int, int> > q;
for (i = 1; i <= k; i++) {
for (j = 0; j < knode[i].size(); j++) {
q.push(make_... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> enemy_data[200000];
vector<pair<long long, long long>> alive[200000];
long long imos[2000000] = {};
int main() {
long long n, m;
scanf("%lld%lld", &n, &m);
long long bounty, inc, dmg;
scanf("%lld%lld%lld", &bounty, &inc, &dmg);
v... | 17 |
#include <bits/stdc++.h>
using namespace std;
int f(string s) {
cout << s << endl;
int r;
cin >> r;
if (r == 0) exit(0);
return r;
}
void solve() {
int qa = f(string(300, 'a'));
int qb = f(string(300, 'b'));
int A = 300 - qa;
int B = 300 - qb;
int last = B;
int l = A + B;
string ans(l, 'a');
f... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = (1 << 30);
int h1[maxn], t1[maxn];
int h2[maxn], t2[maxn];
int mark[maxn][maxn];
int d[maxn][maxn];
int h, t, R;
int n, m;
int bfs() {
for (int i = 0; i <= R; i++)
for (int j = 0; j <= R... | 13 |
#include <bits/stdc++.h>
using namespace std;
multiset<long long> servers;
int n, k, t, len;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < k; i++) {
servers.insert(0);
}
for (int i = 0; i < n; i++) {
scanf("%d%d", &t, &len);
long long best = *servers.begin();
servers.erase(servers.begi... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5 + 1;
inline int read() {
char c;
int out = 0;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
;
for (; c >= '0' && c <= '9'; c = getchar()) {
out = (out << 3) + (out << 1) + c - '0';
}
return out;
}
int tt[Maxn], num[Maxn];
in... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, r;
cin >> n >> r;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long sum = 1, k = 1;
for (long long i = n - 2; i >= 0; i--) {
if (a[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int SieveOfEratosthenes(int **arr, int n) {
int c = 0;
int *ar;
ar = (int *)malloc(sizeof(int *) * n);
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * 2; i <= n; i += p)... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long dp[4000005];
void solve() {
long long n, m;
cin >> n >> m;
dp[1] = 1;
dp[2] = 2;
dp[3] = 5;
long long tsm = 8;
for (long long i = 4; i < n + 1; i++) {
long long ans = tsm;
long long ls = 1;
for (long long j = 2... | 9 |
#include <bits/stdc++.h>
using namespace std;
int64_t factorial(int64_t n) {
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
int64_t power(int64_t x, int64_t y) {
int64_t res = 1;
while (y > 0) {
if (y & 1) res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
int64_t powerMod(int64_t x, i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
map<double, int> m;
vector<double> v;
while (n--) {
char ch;
double a, b, c;
cin >> ch >> a >> ch >> b >> ch >> ch >> c;
m[(a + b) / c]++;
v.push_back((a + b) / c);
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > g;
vector<long long int> vis, par, ans, ans2;
void solve() {
long long int i, j, k, x, n, c = 0, y, ans = 0, q;
cin >> n >> q;
map<long long int, long long int> m;
vector<long long int> a(n);
long long int dp[n][3];
for (i = 0; i <... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.141593;
const long long mod = 1000000007;
const long long INF = 1e15;
const long long nax = 1e5 + 5;
long long dx[] = {0, 0, 1, -1};
long long dy[] = {1, -1, 0, 0};
string ds = "RLDU";
long long parent[200001] = {0};
long long size[200001] = {0};
ve... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
vector<string> w(8);
for (int i = 0; i < 8; ++i) {
cin >> w[i];
}
set<pair<pair<int, int>, int> > s, s2;
pair<int, int> start, finish;
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 8; ++j) {
if (w[i][j] == 'M') {
start ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int n;
vector<pair<pair<long long, long long>, int>> vc;
long long mx[3000];
int popcnta(int a) {
int v = 0;
while (a) {
v += a & 1;
a >>= 1;
}
return v;
}
int main(int argc, char **argv) {
ios::sync_with_stdio(0);
cin >... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const int N = 1e6 + 10;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
char s[N];
long long base = 10;
long long v[N], b[N];
void init(int n) {
b[0] = 1, v[0] = (s[0] - '0');
for (int i = 1; i < n; ++i) {
b[i] = b[i - 1]... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
unsigned long long i, j, n, m, ans = 0, temp = 0, l, r, f = 0;
cin >> l >> r;
if (l == r && l == 0)
cout << "0\n";
else {
for (i = 1; i <= 1000000000000000000; i *= 2) {
temp += i;
... | 9 |
#include <bits/stdc++.h>
using std::cin;
using std::cout;
const int N = 200200;
int n, m;
int a[N], x[N];
std::unordered_map<int, int> map;
inline int ask0(int id, unsigned l);
inline int ask1(int id, unsigned l);
inline int gr(int id, int l) {
return std::upper_bound(x + 1, x + n + 1, x[id] + l) - x - 1;
}
inline in... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T in() {
char ch;
T n = 0;
bool ng = false;
while (1) {
ch = getchar();
if (ch == '-') {
ng = true;
ch = getchar();
break;
}
if (ch >= '0' && ch <= '9') break;
}
while (1) {
n = n * 10 + (ch - '0');
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string res = "";
int sf = 100000000, cf = 100000000, s, c;
int N;
cin >> N;
for (int i = 0; i < 200000; ++i) {
if ((N - 7 * i) >= 0 && (N - 7 * i) % 4 == 0) {
s = i;
c = (N - 7 * i) / 4;
if (s + c < sf + cf) {
sf = s;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
const long long N = 1e3 + 1;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
char x;
int cnt;
int n, m;
int a[N][N];
int l, r, mi;
vector<int> a1, a2, a3;
int ud[N][N], lr[N][N];
int tud[N][N], tlr[N][N];
bool can(int m, int i, int j... | 11 |
#include <bits/stdc++.h>
using namespace std;
int dp[1000001] = {0};
int solve(int num) {
if (!num) return 0;
if (num <= 9)
return 1;
else if (dp[num] != -1)
return dp[num];
int ret = INT_MAX;
int digs[10] = {0};
int t = num;
while (t) {
digs[t % 10] = 1;
t /= 10;
}
for (int i = (int)(... | 3 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d, e = 0;
scanf("%d %d", &a, &b);
for (c = 0; c <= 40; ++c) {
for (d = 0; d <= 40; ++d) {
if (c * c + d == a && c + d * d == b) ++e;
}
}
printf("%d\n", e);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
int n = s.size();
for (int i = 0; i < n; i += 2) {
cout << s[i];
}
cout << s[n - 1];
cout << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x1, x2, y1, y2, i, j, m1, m2, dis = 0;
double m;
cin >> x1 >> y1 >> x2 >> y2;
m1 = abs(x2 - x1);
m2 = abs(y2 - y1);
if (m1 == m2) {
cout << m1;
} else if (m1 < m2) {
cout << m2;
} else {
cout << m1;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
using namespace std;
const int maxn = 100005 * 2;
constexpr int mdn = 998244353;
struct mint {
int v;
inline operator int() const { return v; }
inline mint(int v = 0) : v(v) {}
inline bool operator==(const mint& a) const { return v == a.v; }
inline bool ... | 16 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int SIZE = (1 << 20) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = obuf + SIZE - 1;
char _st[55];
int _qr = 0;
inline char gc() {
return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
(iS == iT ? EOF : *iS++) : *... | 3 |
#include <bits/stdc++.h>
using namespace std;
int N, M, a[1005];
double f[1005][1005];
void init() {
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
}
void doit() {
int k = 0;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++) f[i][j] = a[i] > a[j];
for (int i = 1, u, v; i <... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, ai, b[maxn];
pair<int, int> a[maxn];
bool cmp(pair<int, int> a, pair<int, int> b) { return a > b; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &ai), a[i] = make_pair(ai, i);
for (int i = 1; i <= n; i++) scan... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
string s0 = s;
auto p = unique(s0.begin(), s0.end());
if (p == s0.begin() + 1) {
cout << -1 << endl;
} else {
sort(s.begin(), s.end());
cout << s << en... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 2e9;
const long long INFLL = 1e18;
const int MAX_N = 1000;
int N, M;
long long K, P;
long long arr[MAX_N + 1][MAX_N + 1];
long long sum[2][MAX_N + 1];
priority_queue<long long> pq;
vector<long long> mx[2];
long long ans = -INFLL;
... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const long long maxn = (long long)1e6 + 5;
const long long mod = 1000000007;
const long long inf = 0x3f3f3f3f;
long long g[1005][1005];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, a, b... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int len, dp[501][5001], k, ara[11], cur;
int ad2[100001], n, ad3[100001];
long long int mod = 1e9 + 7;
long long int bigmod(long long int a, long long int b) {
long long int res = 1;
while (b) {
if (b % 2) res = (res * a) % mod;
a = (a * a) % mod, b /=... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i = 0, p, j = 1;
cin >> n;
int arr[n], arr2[n], arr3[n];
if (n % 2 == 0) {
cout << "-1";
} else if (n == 1) {
cout << "0"
<< "\n"
<< "0"
<< "\n"
<< "0";
} else {
p = (n / 2) + 1;
while (i <=... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long n, k, a[5] = {1, 2, 3, 5};
int main() {
ios::sync_with_stdio(0);
cin >> n >> k;
cout << k * (6 * (n - 1) + 5) << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++) cout << k * (6 * i + a[j]) << " ";
cout << e... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[8], b[8], c[8];
int ar[8], br[8], cr[8], bs[8];
long long dist(long long a, long long b) { return (a - b) * (a - b); }
int check(int n) {
int nc = n;
for (int i = 0; i < 8; i++) {
bs[i] = nc % 6;
nc /= 6;
}
for (int i = 0; i < 8; i++) {
if (bs[i] =... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
void solve() {
cin >> a >> b >> c >> d;
long long k = a / (b * d);
if (a > c * b)
cout << "-1" << endl;
else
cout << a * (k + 1) - (((k + 1) * k) / 2) * (b * d) << endl;
}
int main() {
long long t;
cin >> t;
while (t--) solve();
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int64_t N = 100 * 1000;
int64_t a[N + 3];
int64_t b[N + 3];
int64_t f(int64_t n) {
if (n < 0) return -n;
return n;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int64_t n, m, q;
cin >> n >> m >> q;
for (int64_t i = 1; i <= n; ++i) cin >> a[i];
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int d[65][65][65], c[65][65][1005];
int main() {
int n, m, r;
cin >> n >> m >> r;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
scanf("%d", &d[j][k][i]);
}
}
for (int j = 1; j <= n; j++) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
int prime[MAXN + 10];
int hsh[MAXN + 10];
int n, cnt, lst;
int read(void) {
scanf("%d", &n);
return 0;
}
int init(void) {
lst = cnt = 0;
hsh[0] = hsh[1] = 1;
for (int i = 2; i <= 1000000; i++) {
if (!hsh[i]) prime[++cnt] = i;
for ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 11 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<pair<long long, long long> > v, ans;
map<pair<long long, long long>, long long> mp;
for (l... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N, P, dp[1001][2][27][27];
string s, output = "";
int solve_for(int idx, int restriction, int prev_val, int prev_to_prev_val) {
if (idx >= N) return (!restriction);
if (dp[idx][restriction][prev_val][prev_to_prev_val] != -1)
return dp[idx][restriction][prev_val]... | 9 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <typename T>
void rd(T& x) {
int f = 0, c;
while (!isdigit(c = getchar())) f ^= !(c ^ 45);
x = (c & 15);
while (isdigit(c = getchar())) x = x * 10 + (c & 15);
if (f) x = -x;
}
template <typename T>
void pt(T x, int c = -1) {
if (x ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3000001;
int n, m, freq[N];
long long cum[N];
int main(int argc, char **argv) {
scanf("%d", &n);
for (int i = 0, x; i < n; ++i) {
scanf("%d", &x);
++freq[x];
}
for (int i = 1; i < N; ++i) {
if (!freq[i]) continue;
for (int j = i; j < N;... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 2000000000;
const long long BIG = 1446803456761533460LL;
const int maxn = 300010;
const int MAX = 1000000000;
const int maxnlg = 30;
int n, m;
bool notsat[maxn], modify[maxn], chg[maxn];
int cnt[maxn], dup[maxn], dn;
pair<int, int... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
int n, ans = 1;
int a[N], b[N], ls[N];
int s[N << 2];
void mdf(int p, int l, int r, int x, int d) {
if (l == r) {
s[p] = d;
return;
}
int mid = l + r >> 1;
if (x <= mid)
mdf(p << 1, l, mid, x, d);
else
mdf(p... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long x, y, z, t1, t2, t3;
cin >> x >> y >> z >> t1 >> t2 >> t3;
long long stair = abs(x - y) * t1;
long long elevator = 3 * t3 + abs(z - x) * t2 + abs(x - y) * t2;
if (elevato... | 0 |
#include <bits/stdc++.h>
using namespace std;
string a;
int main() {
int n;
cin >> n;
while (n--) {
cin >> a;
int i1 = 0, j1 = 0, k1 = 0;
for (int i = 0; i < a.size(); i++) {
if (a[i] == 'A')
i1++;
else if (a[i] == 'B')
j1++;
else if (a[i] == 'C')
k1++;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, element;
unordered_set<int> st;
cin >> n;
while (n--) {
cin >> element;
st.insert(element);
}
if (st.size() > 3) {
cout << "NO";
return 0;
} else if (st.size() <= 2) {
... | 4 |
#include <bits/stdc++.h>
int a[400], b[400];
char c[6000];
int main() {
int n, l, r, max1 = 0, max2 = 0;
scanf("%d", &n);
getchar();
for (int i = 1; i <= n; i++) {
scanf("%c", &c[i]);
getchar();
scanf("%d", &l);
scanf("%d", &r);
if (c[i] == 'M') {
a[l] = a[l] + 1;
a[r + 1] = a[r ... | 3 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[200005];
int b[200005];
void fun(int l, int r) {
if (l > r) return;
int m = (l + r) / 2;
a[m].first = l - r;
a[m].second = m;
fun(l, m - 1);
fun(m + 1, r);
}
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
fun(1, n);
s... | 8 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long n, k;
cin >> n >> k;
set<long long> s;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (long long i = n - 1; i >= 0; i--) {
if (!s.count(a[i] * k)) s.insert(a[i]);
}
cout << s.size();
retu... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100009;
int maxup[MAXN];
int main() {
int n, tmp, maxl = 0;
int *ptr;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> tmp;
ptr = upper_bound(maxup, maxup + maxl, tmp);
*ptr = tmp;
if (ptr == maxup + maxl) maxl++;
}
cout << maxl <<... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct E {
int to, next, w;
} e[600005];
priority_queue<tuple<long long, int>, vector<tuple<long long, int>>,
greater<tuple<long long, int>>>
pq;
queue<int> q;
vector<int> nxt[200005], rev[200005];
int n, m, s, cnt, ans, hd[200005], deg[200005], vis[200... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long int isPrime(long long int n) {
long long int p = (long long int)sqrt(n);
for (long long int i = (2); i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
long long power(long long a, long long n) {
long long p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
lon... | 2 |
#include <bits/stdc++.h>
int main() {
int i, n;
scanf("%d", &n);
int rating[n], result[n], temp = 0;
for (i = 0; i < n; i++) {
scanf("%d", &rating[i]);
}
int balance = 0;
for (i = 0; i < n; i++) result[i] = floor(rating[i] / 2);
for (i = 0; i < n; i++)
if (rating[i] < 0 && rating[i] % 2 != 0) re... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 5, MOD = 1e9 + 9;
long long dp[N][N][15];
map<char, long long> m;
long long arr[N][4], fail[N], cnt[N], pos;
void insert(string &s) {
long long now = 0;
for (auto c : s) {
long long &to = arr[now][m[c]];
now = to ? to : to = ++pos;
}
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int a[16];
int f[16][1 << 15 | 1], g[16][1 << 15 | 1], sum[1 << 15 | 1], p[16];
vector<int> x, y;
vector<int> ff[16], out[16];
void solve() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
int o = n;
for (int i = 0; i < n; i++) ff[i].clear... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, tbreak, tjoy, ttake, mx = -9999999999;
cin >> n >> tbreak;
while (n--) {
cin >> tjoy >> ttake;
if (ttake <= tbreak)
mx = max(mx, tjoy);
else
mx = max(mx, tjoy - (ttake - tbreak));
}
cout << mx;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<long long, int> h[30];
char s[N];
int val[30];
long long ans, sum[N];
int main() {
for (int i = 0; i < 26; ++i) scanf("%d", val + i);
scanf("%s", s + 1);
int vfk = strlen(s + 1);
for (int i = 1; i <= vfk; ++i) {
ans += h[s[i] - 'a'][su... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, i, co = 0, odd = 0, in;
cin >> n;
int arr[n], dp[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
dp[i] = 0;
}
for (i = 0; i < n; i++) {
if (arr[i] % 2 == 0) {
dp[i] = 1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
inline long long read() {
register char c = getchar();
register long long x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + c - '0';
c = getchar... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
long long int n, q;
cin >> n >> q;
for (int Q = 0; Q < q; Q++) {
long long int x;
cin >> x;
if (x % 2 == 1) {
cout << (x + 1) / 2 << ' ';
continue;
}
x = n - x / 2;
while (x % 2 == 0) x /= 2;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int x, y;
cin >> x >> y;
long long int i = 0;
long long int k = y;
set<pair<long long int, long long int>> second;
while (i <= 100) {
if (i <= x && k >= 0 && i + k > 0) {
second.insert(make_pair(i, k));
}
i += 1;
k-... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 1e6 + 10;
const int M = 1e9 + 7;
const double eps = 1e-5;
inline long long qpow(long long a, long long b, long long m) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a)... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
int n, m;
cin >> n >> m;
vector<int> a;
vector<int> b;
for (int i = 0; i < n; ++i) {
int u;
cin >> u;
a.push_back(u);
}
for (int i = 0; i < m; ++i) {
int u;
cin >> u;
b.push_back(u);
}
map<int,... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 30004;
const int inf = 1e9;
struct node {
int x;
int id;
} w[N], h[N];
bool comp(node a, node b) { return a.x < b.x; }
long long int add[N][4];
int idh[N];
long long int dp[N];
void update(int i) {
add[i][0] = add[i][1] = add[i][2] = -inf;
if (w[i].id ... | 22 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 2 |
#include <bits/stdc++.h>
using namespace std;
void fileio() {}
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
void solve() {
long long int n;
cin >> n;... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100001], res;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
res = n - 1;
for (int i = n - 2; i >= 0; --i)
if (a[i] < a[i + 1])
res = i;
else
break;
cout << res;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, s = 0, i, digs = 1;
i = 1;
cin >> n;
while (i * 10 <= n) {
s += digs * (i * 10 - i);
digs++;
i *= 10;
}
s += (n - i + 1) * digs;
cout << s << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct T {
ll l, r;
int id;
};
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<T> v;
for (int i = 0; i < n; ++i) {
ll x, y;
cin >> x >> y;
v.push_back({x, y, i});
}
sort((v).begin(), (v).end(), [](co... | 7 |
#include <bits/stdc++.h>
using namespace std;
int modulo;
int getAns(long long start, long long delta, long long n, long long left,
long long right, long long lower, long long upper) {
if (n == 1) {
return (lower <= start && start <= upper) ? start % modulo : 0;
} else if (left == 0 && right == n - 1... | 17 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() { return getchar(); }
template <class T>
int read(T &ans) {
ans = 0;
char ch = gc();
T f = 1;
while (!isdigit(ch)) {
if (ch == EOF) return -1;
if (ch == '-') f = -1;
ch = gc();
}
while (isdigit(ch)) ans = ans * 10 + ch - '0', ch = gc... | 21 |
#include <bits/stdc++.h>
using namespace std;
void sortString(string &str) { sort(str.begin(), str.end()); }
int main() {
string s;
cin >> s;
long long same = 1;
long long total = 0;
sortString(s);
for (int i = 0; i < (s.size()); i++) {
if (s[i] == s[i + 1]) {
same++;
} else {
total += (... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 20000;
int main() {
int n, m, ct;
static int a[MaxN + 1];
cin >> n >> m >> ct;
for (int i = 1; i <= n; i++) {
int hh, mm, ss;
scanf("%d:%d:%d", &hh, &mm, &ss);
a[i] = (hh * 60 + mm) * 60 + ss;
}
bool ok = false;
int nC = 0;
stati... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = atan(1.0) * 4;
const int64_t INF = 8e18;
const int32_t LOG = 21;
const long long int MOD = 998244353;
vector<long long int> v[200005];
vector<long long int> vt[200005];
long long int state[200005];
bool check1[200005];
bool check2[200005];
bool cycle ... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &x) {
return os << "(" << x.first << "," << x.second << ")";
}
namespace dbg_ns {
template <typename C>
struct is_iterable {
template <class T>
static long check(...);
template <class T>
... | 12 |
#include <bits/stdc++.h>
using namespace std;
double x[1003];
double y[1003];
map<double, int> mop;
map<pair<double, double>, int> mpp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
double yy;
long long int tot = 0, uniq = 0;
for (int i = 0; i < n; i++) {
cin >> x[i] >... | 11 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long int mod = 1000000007;
unsigned long long int arr[300005];
int main() {
unsigned long long int n;
cin >> n;
unsigned long long int ans = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (i != 0) {
arr[i] = arr[i] ^ arr[i - 1];
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t = {};
int n = {};
int m = {};
cin >> t;
while (t--) {
cin >> n >> m;
if (n == 1) {
cout << "YES" << endl;
} else if (m == 1) {
cout << "YES" << endl;
} else if (m < 3 && n < 3) {
cout << "YES" << endl;
} els... | 0 |
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int T;
int n, m, B;
int a[N], vis[N], cnt[N];
vector<int> c[N], b[N];
typedef pair<int, int> pii;
void solve()
{
fill(vis+1, vis+m+1, 0);
for (int i=1; i<=n; i++) if (c[i].size()>=B) {
for (int j:c[i]) vis[j]=1;
for (int j=1; j<=n; j++) {
if(i... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int c = 4005;
long long n, m, t[c], fel[c], dp[c][c], rf[c];
vector<int> sz[c];
void solve(int a, int b, int c) {
if (a > b) {
return;
}
int pos = a;
for (int i = a; i <= b; i++) {
if (t[i] < t[pos]) {
pos = i;
}
}
sz[c].push_back(pos);
... | 21 |
#include <bits/stdc++.h>
using namespace std;
string s;
int i, a[6] = {0}, v = 0;
int main() {
ios_base::sync_with_stdio(false);
cin >> s;
for (i = 0; i < s.length(); i++) {
if (s[i] == 'a')
a[0]++;
else if (s[i] == 'b')
a[1]++;
else if (s[i] == 'l')
a[2]++;
else if (s[i] == 'r')... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, t;
cin >> n;
long long int a[n];
long long int ans = 0;
for (long long int i = 2; i <= n; i++) {
if ((n - i) % i == 0) {
ans++;
}
}
cout << ans;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long c = 0;
for (long long i = 2 * n; i <= 4 * n; i += 2) {
c++;
if (c > n) break;
cout << i << " ";
}
cout << "\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long p) {
long long res = 1;
while (p != 0) {
if (p % 2 == 1) res = (res * b) % 1000000007;
b = (b * b) % 1000000007;
p /= 2;
}
return res;
}
int main() {
long long n, a, b, res;
while (scanf("%I64d", &n) == 1) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < (int)n; i++) cin >> a[i];
vector<long long> b(n);
b[0] = a[0];
for (int i = 0; i < (int)n - 1; i++) b[i + 1] = b[i] + a[i + 1];
sort(b.begin(), b.end());
int m = 0;
int k = 0;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
char ar[500];
int main() {
scanf(" %s", ar + 1);
int disari = 0, iceri = 0, sum = 0;
for (int i = 1; i <= strlen(ar + 1); i++) {
if (ar[i] == '+' && disari) {
disari--;
iceri++;
} else if (ar[i] == '+' && !disari) {
iceri++;
sum++;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, s1, s2, cnt = 0;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
char a[500][500], used[500][500];
bool ok(int i, int j) {
return i >= 0 && i < n && j >= 0 && j < m && a[i][j] == '.' &&
used[i][j] == false;
}
int main() {
ios_base::sync_with_stdi... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cout << fixed << setprecision(12);
long long n, p;
cin >> n >> p;
long long a[n];
long long b[n];
long long cnt = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
cin >> b[i];
cnt += a[i];
}
if (cnt <= p) {
cout << -1 << end... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
struct edge {
int y;
edge *n;
} e... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
int prime[MAXN + 1];
void getPrime() {
memset(prime, 0, sizeof(prime));
for (int i = 2; i <= MAXN; i++) {
if (!prime[i]) prime[++prime[0]] = i;
for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++) {
prime[prime[j] * i] = 1;... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 4;
set<long long> s;
long long h[N];
vector<long long> leaf;
vector<long long> gr[N];
void dfs(long long u, long long p) {
h[u] = h[p] + 1;
for (long long v : gr[u]) {
if (v != p) dfs(v, u);
}
if ((long long)gr[u].size() == 1) {
lea... | 10 |
#include <bits/stdc++.h>
using namespace std;
int table[20][20];
int A[20] = {0, 0, 4, 6, 8, 9, 11, 13, 15, 17};
int a[20][20];
int first_x, last_x, first_y, last_y;
int n, m;
int ans = 0, cur = 0;
void solve(int x, int y) {
if (x > last_x) {
if (cur > ans) {
ans = cur;
for (int i = 0; i <= 15; i++)
... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long cb = 0;
bool vis[400005];
vector<long long> pos[400005];
long long a[400005];
set<pair<long long, long long> > pq;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> k;
for (long long i = 1; i <= n; ... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.