solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; inline long long mod(long long n, long long m) { long long ret = n % m; if (ret < 0) ret += m; return ret; } long long gcd(long long a, long long b) { return (b == 0LL ? a : gcd(b, a % b)); } long long exp(long long a, long long b, long long m) { if (b == 0LL) ret...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 1123456; int x[MAX]; int n; int solve(int a, int b) { int k = 0, j = 0; for (int i = 1; i <= n; i++) { if (x[i] == 1000) a--; else b--; if (x[i] == 1000 && a >= 0 || x[i] == 2000 && b >= 0) { k += x[i], j += x[i] / 10; }...
10
CPP
#include <bits/stdc++.h> int min(int a, int b) { return a < b ? a : b; } int max(int a, int b) { return a > b ? a : b; } int main() { static int aa[300000], pp[300000], ip[300000], iq[300000]; int n, i, i_, ans; scanf("%d", &n); for (i = 0; i < n; i++) { int a; scanf("%d", &a); pp[i] = aa[i] = a; ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long inf = 9.2e18; const int maxn = 300007; const int INF = 2.1e9; const int MOD = 1e9 + 7; const double dif = 1e-7; const double PI = 3.14159265358979323846; int n, m, k, sum = 0; int a[maxn], pre[maxn]; bool check(int x) { int d = sum - k, s = 0, flag1 = 0, f...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, s, cnt, tmp, a[300001]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), s += a[i], cnt += a[i] < 2000; int tmp = s / 1100; if (s <= 11000) tmp = (s - a[n]) / 1000; if (!cnt && tmp & 1) tmp--; return printf("%d\n", s - tm...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXD = 35; int n, a[300005]; long long f[300005][MAXD + 5]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) a[i] /= 100; for (int i = 0; i <= n; ++i) for (int j = 0; j <= MAXD; ++j) f[i][j] = ...
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t, class u> void chmax(t& first, u second) { if (first < second) first = second; } template <class t, class u> void chmin(t& first, u second) { if (second < first) first = second; } template <class t> using vc = vector<t>; template ...
10
CPP
#include <bits/stdc++.h> using namespace std; int f(int p1, int r1, int p, int S) { int a = min(p1 / 10, r1); int res = p1 + r1 - a; int rem = p1 / 10 - a; return res + p - p1 + max(0, S - p - r1 - (p - p1) / 10 - rem); } int main() { int n; scanf("%d", &n); vector<int> a(n); vector<int> s(n + 1); vec...
10
CPP
#include <bits/stdc++.h> using namespace std; int a[300005]; int lastone[300005]; int nextone[300005]; long long sum[300005]; vector<int> vt[3]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); sum[i] = sum[i - 1] + a[i]; lastone[i] = (a[i] == 1000) ? i : lastone...
10
CPP
#include <bits/stdc++.h> using namespace std; int a[300005]; int main() { memset(a, 0, sizeof(a)); int n = 0, total = 0; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); total += a[i] / 1000; } int x = total * 10 / 11; x = min(x, total - a[n - 1] / 1000); bool ck = false; for...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 300000; const int INF = 1000000000; const int MAXV = 40; int n; int a[MAXN]; int dp[2][MAXV + 1]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i <= MAXV; i++) dp[0][i] = INF; dp[0][0] = 0; int t = 0...
10
CPP
#include <bits/stdc++.h> using namespace std; const int Imx = 2147483647; const long long Lbig = 2e18; const int mod = 1e9 + 7; struct fastio { char s[100000]; int it, len; fastio() { it = len = 0; } inline char get() { if (it < len) return s[it++]; it = 0; len = fread(s, 1, 100000, stdin); if (...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = -1; const int INF = 1.01e9; int main() { int n; scanf("%d", &n); vector<int> a(n); for (int i = 0; i < (n); i++) { scanf("%d", &a[i]); } vector<int> pref; pref.push_back(0); for (int i = 0; i < (n); i++) { pref.push_back(pref.back() + a...
10
CPP
#include <bits/stdc++.h> using namespace std; constexpr int MOD = 1000000007; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i...
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 100; const int L = 30; const int oo = 1e9; int N, A[maxn]; int dp[L + 5][maxn]; inline void change(int &ret, int v) { if (ret > v) ret = v; } int solve() { for (int i = (0), _i = (L + 1); i <= _i; i++) for (int j = (0), _j = (N); j <= _j; j++)...
10
CPP
#include <bits/stdc++.h> using namespace std; long long n, ai, summ; vector<long long> data; vector<long long> sums, nexts, prevs; bool checker(long long mid) { long long ww = mid; if (mid * 11 > summ) return false; long long gr; for (long long i = n - 1; i >= 0; i--) { if (data[i] > mid) { gr = i; ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7, inf = 1e9 + 7; int a[N], dp[2][50], now, n; void gmin(int &a, int b) { if (a > b) a = b; } int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", a + i), a[i] /= 100; now = 0; for (int i = 1; i <= 40; ++i) dp[now][i] = inf; ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 300000 + 10; const int MAXY = 40; int N; long long DP[MAXN][MAXY + 1]; void Work() { scanf("%d", &N); memset(DP, 1, sizeof(DP)); DP[0][0] = 0; for (int i = 1; i <= N; i++) { int ai, add; scanf("%d", &ai); ai = ai / 100; add = ai / 10...
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) cin >> a[i]; long long res = 1LL << 55; vector<long long> psum(n + 1); for (int i = 0; i < n; i++) psum[i + 1] = psum[i] + a[...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class P, class Q> inline void smin(P &a, Q b) { if (b < a) a = b; } template <class P, class Q> inline void smax(P &a, Q b) { if (a < b) a = b; } const int maxn = 300000 + 100; int n; int a[maxn], s[maxn]; int main() { ios_base::sync_with_stdio(false); cin...
10
CPP
#include <bits/stdc++.h> using namespace std; int Stv[1 << 8]; inline int read() { int f = 1, res = 0, ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar(); return f * res; } int n, f[2][35]; int...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 3e5; long long n, a[N], dp[N][40]; void solveTestCase() { for (long long i = 0; i < N; i++) { for (long long j = 0; j < 40; j++) dp[i][j] = 1e18; } cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; if (a[0] == 1000) dp[0][1] = 10...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int n; long long a[MAXN], dp[MAXN][35]; inline void chkmin(long long& x, long long y) { if (y < x) x = y; } int main() { scanf("%d", &n); for (long long i = 0; i < n; i++) { scanf("%lld", &a[i]); } memset(dp, 127 / 2, sizeof(dp)); dp...
10
CPP
#include <bits/stdc++.h> using namespace std; char ch; int n, a[300002]; long long f[300002][41], ans; inline void read(int &x) { x = 0; do { ch = getchar(); } while (ch < '0' || '9' < ch); do { x = x * 10 + ch - '0'; ch = getchar(); } while ('0' <= ch && ch <= '9'); } inline void read(long long &...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 4, M = 31, INF = 1e9; int n, a[N], dp[N][M]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], a[i] /= 100; for (int i = 0; i <= n; i++) for (int j = 0; j < M; j++) dp[i][j] = INF; dp[0][0] = 0; for (int i = 0; i < n; i++) ...
10
CPP
#include <bits/stdc++.h> using namespace std; char ch; int n, a[300002]; long long f[300002][41], ans; inline void read(int &x) { x = 0; do { ch = getchar(); } while (ch < '0' || '9' < ch); do { x = x * 10 + ch - '0'; ch = getchar(); } while ('0' <= ch && ch <= '9'); } inline void read(long long &...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, sum, ans, aans, now; int main() { cin >> n; for (int x = 1; x <= n; x++) cin >> now, sum += now / 1000, ans += (now == 1000); if (sum <= 11) aans = sum - now / 1000; else aans = sum * 10 / 11; cout << sum * 1000 - (aans - (!ans && aans % 2 == 1)...
10
CPP
#include <bits/stdc++.h> using namespace std; int N; int A[303030]; signed long long dp[303030][32]; void solve() { int i, j, k, l, r, x, y; string s; scanf("%d", &N); for (i = 0; i < (N); i++) scanf("%d", &A[i]), A[i] /= 100; for (i = 0; i < (N + 1); i++) for (j = 0; j < (32); j++) dp[i][j] = 1LL << 60; ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7; int n, ans; int a[N], f[N][35]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); memset(f, 60, sizeof f); ans = f[0][0]; f[0][0] = 0; for (int i = 0; i < n; i++) for (int j = 0; j <= 30; j++) { f[i + ...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, a[300300]; int total = 0, cnt1 = 0, cnt2 = 0; int before[300300]; inline int countBonus(int x, int y) { return min(x * 100 + y * 200, (cnt1 - x) * 1000 + (cnt2 - y) * 2000); } int main() { int maxBonus = 0, current; int l, r, mid1, mid2, b1, b2; scanf("%d", &...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const long long inf = 1e18; int n; int a[N]; int dp[N]; int dpn[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 0; i <= 30; i++) { dp[i] = int(1e9); dpn[i] = int(1e9); } dp[0...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXD = 31; int n, a[300005]; long long f[300005][MAXD + 5]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) a[i] /= 100; for (int i = 0; i <= n; ++i) for (int j = 0; j <= MAXD; ++j) f[i][j] = ...
10
CPP
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = getchar(); int x = 0, op = 1; while (ch < '0' || '9' < ch) { if (ch == '-') op = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); int x = 0; } return op * x; } const...
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> bool mini(A &x, const B &y) { if (y < x) { x = y; return true; } return false; } template <typename A, typename B> bool maxi(A &x, const B &y) { if (y > x) { x = y; return true; } return false; } class fastio { ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 300005; const long long inf = (1e15); long long f[N][50], n, a[N]; signed main() { cin >> n; for (register long long i = (1); i <= (n); ++i) cin >> a[i], a[i] /= 100; memset(f, 0x3f, sizeof(f)); f[0][0] = 0; for (register long long i = (1); i <...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 0, M = 0; int read() { char c; int num, f = 1; while (c = getchar(), !isdigit(c)) if (c == '-') f = -1; num = c - '0'; while (c = getchar(), isdigit(c)) num = num * 10 + c - '0'; return num * f; } int n, f[300009][31]; void up(int &x, int y) { ...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T, class U> void smin(T &a, U b) { if (a > b) a = b; } const long long mod = 1000000007; const int N = 3e5 + 10; const int M = 2e6; int n, a[N], dp[N][66]; int main() { cin >> n; for (int i = 0; i <= n - 1; i++) { scanf("%d", a + i); a[i] /= 10...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, tot, tmp, sum, a[5000005]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i] == 1000) tot++, sum++; else sum += 2; } int tmp = 10 * sum / 11; if (sum <= 11) tmp = sum - a[n] / 1000; if (!tot ...
10
CPP
#include <bits/stdc++.h> int n, sum, tot, ans; int a[400400]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", a + i); sum += a[i] / 1000; tot += (a[i] == 1000); } int temp = sum * 10 / 11; if (sum <= 11) temp = sum - a[n] / 1000; if (!tot && temp % 2 == 1) temp--; prin...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5, mod = 1e9 + 7; int koszt[31], tmp[31]; int main() { int a, b, c, d, e, f, g, z, k, n, m, q; scanf("%d", &n); for (a = 1; a <= 30; a++) koszt[a] = 1000000000; while (n--) { scanf("%d", &a); if (a == 1000) { for (b = 0; b <= 30;...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T> void debug(T a, T b) { ; } template <class T> void chmin(T& a, const T& b) { if (a > b) a = b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } namespace std { template <class S, class T> ostream& operator<<(ostream& out, cons...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; int n, pos1Size = 0, pos2Size = 0; int ar[N], pos1[N], pos2[N]; struct Node { int S, M; Node() {} Node(int S, int M) : S(S), M(M) {} }; Node st[3 * N]; void Update(int k, int v) { k += (1 << 19); st[k] = Node(v, ...
10
CPP
#include <bits/stdc++.h> using namespace std; void addmod(int &a, long long b) { a = (a + b); if (a >= 1000000007) a -= 1000000007; } void mulmod(int &a, long long b) { a = (a * b) % 1000000007; } template <class T> bool domin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool domax(T &a, ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXC = 305; const int MAXN = 300005; const int INF = 1000000000; int A[MAXN], dp[2][MAXC]; int main(int argc, char const *argv[]) { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &A[i]); A[i] /= 100; } for (int i = 0; i < MAXC...
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (...
10
CPP
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 300000; int n; int a[MAXN]; int dp[MAXN + 1][31]; void upd(int &a, int b) { if (a == -1 || b > a) a = b; } void run() { scanf("%d", &n); for (int i = (0); i < (n); ++i) sca...
10
CPP
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } long long n...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long linf = 1e18 + 5; int mod = (int)1e9 + 7; const int logN = 18; const int inf = 1e9 + 9; const int N = 4e5 + 6; int dp[N][105], a[N], n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int x = n; x >= 1; x--)...
10
CPP
#include <bits/stdc++.h> using namespace std; void getint(int &v) { char ch, fu = 0; for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ; if (ch == '-') fu = 1, ch = getchar(); for (v = 0; ch >= '0' && ch <= '9'; ch = getchar()) v = v * 10 + ch - '0'; if (fu) v = -v; } const int INF = 1e9...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 2; int ar[N], num1, num2, n; vector<int> pos[2]; struct node { int sum, minpre; }; node it[N << 2]; void tag(int idx, int l, int r) { if (l < r) { it[idx].sum = it[2 * idx].sum + it[2 * idx + 1].sum; it[idx].minpre = min(it[2 * idx].m...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 300005, M = 30; int a[N], f[N][M + 5], j, n, i, ans, t; inline void up(int& a, int b) { if (!a || a > b) a = b; } int main() { scanf("%d", &n); for (i = 1; i <= n; ++i) scanf("%d", a + i), a[i] /= 100; for (i = 0; i < n; ++i) for (j = 0; j <= M; ++...
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void chkmax(T& x, U y) { if (x < y) x = y; } template <typename T, typename U> inline void chkmin(T& x, U y) { if (y < x) x = y; } int dp[2][60]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= 41; i++) dp[0][i] =...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long inf = 9.2e18; const int maxn = 300007; const int INF = 2.1e9; const int MOD = 1e9 + 7; const double dif = 1e-7; const double PI = 3.14159265358979323846; int n, m, k, sum = 0; int a[maxn], pre[maxn]; bool check(int x) { int d = sum - k, s = 0, flag1 = 0, f...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, m, ans, two, one, l, r, k, a[N], dp[N][205]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); a[i] /= 100; } memset(dp, 127, sizeof(dp)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (in...
10
CPP
#include <bits/stdc++.h> using namespace std; long long n; long long a[300005]; long long dp[300005][105]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long(i) = (1); (i) <= (n); (i)++) cin >> a[i], a[i] /= 100; for (long long(i) = (0); (i) <= (n); (i)++) for (long long(j) = (...
10
CPP
#include <bits/stdc++.h> using namespace std; const int inf = 1000000007; const long long linf = 1ll * inf * inf; const int N = 300000 + 7; const int M = 32; const int multipleTest = 0; int dp[N][M]; int n; int a[N]; void solve() { cin >> n; for (int i = (0), _b = (N); i < _b; ++i) for (int j = (0), _b = (M); j...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15; const int maxn = 3e5 + 10; long long dp[maxn][55], a[maxn]; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%I64d", &a[i]); a[i] /= 100; } for (int i = 0; i <= n; i++) for (int j = 0; j <= 42; j++) d...
10
CPP
#include <bits/stdc++.h> using namespace std; long long a[300100]; long long sum[300100]; int main() { long long ans = 0; int flag1 = 0, flag2 = 0; memset(a, 0, sizeof(a)); memset(sum, 0, sizeof(sum)); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] != 1000) flag1 = 1; if ...
10
CPP
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; long long a[n + 1]; for (long long i = 1; i <= n; i++) { cin >> a[i]; a[i] /= 100; } long long dp[n + 1][35]; dp[0][0] = 0; for (long long i = 1; i < 35; i++)...
10
CPP
#include <bits/stdc++.h> using namespace std; const int max_n = 300033, max_m = 41, inf = 1011111111; int n, a[max_n], dp[2][max_m]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); a[i] /= 100; } int q1 = 0, q2 = 1; for (int j = 0; j < max_m; ++j) { dp[q1][j] = inf;...
10
CPP