solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
#include <bits/stdc++.h>
using namespace std;
long long n, m, ai, bi;
vector<long long> one, two, three;
int32_t main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (long long i = 0; i < n; i++) {
cin >> ai >> bi;
if (ai == 3)
three.push_back(bi);
else if (ai == 2)
two.push_back(... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
priority_queue<int> q[4];
int n, w;
long long dp[4][300003];
void fun1() {
int k = q[1].size();
for (int i = 1; i <= k && i <= w; i++) {
dp[1][i] = dp[1][i - 1] + q[1].top();
q[1].pop();
}
for (int i = k + 1; i <= w; i++) dp[1][i] = dp[1][i - 1];
}
void fun2... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const long long LINF = 1LL << 60;
long long mod = 1e9 + 7;
char READ_DATA;
int SIGNAL_INPUT;
template <typename Type>
inline Type ru(Type &v) {
SIGNAL_INPUT = 1;
while ((READ_DATA = getchar()) < '0' || READ_DATA > '9')
if (READ_DATA == '-')
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
int n, m, a, b;
long long c[3][maxn];
long long sum[3][maxn];
int cnt[3];
long long cal(int n3, int n2) {
return sum[2][n3] + sum[1][n2] + sum[0][min(cnt[0], m - n3 * 3 - n2 * 2)];
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; ++i) {
s... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
struct node {
int w;
long long c;
bool operator<(const node &r) const {
return c * r.w > r.c * w || c * r.w == r.c * w && w < r.w;
}
} e[maxn];
long long t[maxn];
long long a[maxn];
int f[maxn];
long long mi[maxn];
bool cmp(long long a,... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long v, s1, s2;
} dp[300005];
long long goods[4][300005];
long long num[4];
long long sum[300005];
int cmp(long long a, long long b) { return a > b; }
int main() {
long long n, m, w, c;
while (~scanf("%lld %lld", &n, &m)) {
memset(goods, 0, size... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long ans, dp[N];
int ed, n, m;
struct node {
int w, c;
double val;
node(int a = 0, int b = 0) : w(a), c(b) {}
bool operator<(const node &b) const { return val > b.val; }
} a[N], tmp[N];
long long DP() {
for (int i = 1; i <= ed; i++) {
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000, M = 300000;
long long dp[M + 1][3];
vector<int> c[3];
int main() {
int n, m;
scanf("%d%d", &n, &m);
int ci, wi;
for (int i = 0; i < n; ++i) {
scanf("%d%d", &wi, &ci);
c[wi - 1].push_back(ci);
}
for (int i = 0; i < 3; ++i) sort(c[i].... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using UI = unsigned int;
using UC = unsigned char;
using VI = std::vector<int>;
using SI = std::set<int>;
using PI = std::pair<int, int>;
using PL = std::pair<LL, LL>;
constexpr LL MOD = 1000000009;
constexpr double EXP ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> v[4];
vector<long long> sum[4];
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n >> m;
for (long long i = 0; i < n; i++) {
long long w, c;
cin >> w >> c;
v[w].push_back(c);
}
for (lon... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[4];
long long _1[300300], sum[4][100100], total;
int main() {
ios_base::sync_with_stdio(0);
long long n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
total += x;
v[x].push_back(y);
}
for (int i = 1; i <= ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> w[4];
int n, m;
long long GetAns(int t) {
int totw = m;
long long ans = 0;
for (int i = 0; i < min(t, (int)w[3].size()); i++) {
totw -= 3;
ans += w[3][i];
}
if (totw < 0) return 0;
int p1 = 0, p2 = 0;
while (totw >... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > a;
vector<pair<long long, long long> > b;
vector<pair<long long, long long> > c;
long long n, m;
bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
return x.second * y.first < x.first * y.second;
}
long long left__[5... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct Suv {
long long w, c;
double rate;
};
bool operator<(Suv a, Suv b) { return a.rate < b.rate; }
Suv a[100001];
long long dp[300010];
long long up, down, ans;
int i, j, n, m, c, w;
int main() {
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%d %d"... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long w, c;
};
bool comp(node i, node j) { return (i.c > j.c); }
long long dp[300020];
long long ans;
node arr[100005];
int main() {
long long i, j, n, m;
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> arr[i].w >> arr[i].c;
arr[i].c = ((ar... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e5 + 5;
long long f[mxn], s[mxn], t[mxn];
int n, m, cf, cs, ct;
int nf, ns;
signed main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
int x, y;
cin >> x >> y;
if (x == 1)
f[++cf] = y;
else if... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long val;
int cnt1, cnt2;
} dp[300005];
long long v1[100005], v2[100005], v3[100005];
long long s[100005];
inline bool cmp(long long a, long long b) { return a > b; }
int cnt1 = 0, cnt2 = 0, cnt3 = 0;
int main() {
int n, m, i, k;
long long w;
sc... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 7;
int n, m;
vector<long long> costs[4];
long long sum[4][MAX];
long long f(int a, int w) {
long long ans = sum[2][a];
w -= 2 * a;
w = min(w, (int)costs[1].size());
ans += sum[1][w];
return ans;
}
long long func(int w) {
int beg = 0;
int ... | 11 | CPP |
#include <bits/stdc++.h>
int n, m, vs[4][100007], vp[4];
long long s1[100007], s2[100007], ans = 0, now = 0;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
int x, y;
scanf("%d%d", &x, &y);
vs[x][++vp[x]] = y;
}
for (int i = 1; i <= 3; ++i)
std::sort(vs[i] + 1, vs[i] + vp[i] +... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& a4, C b4) {
a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
return out << "(" << pair.first << ", " << pair.second ... | 11 | CPP |
n,m = map(int,input().split())
a = [[],[],[]]
for _ in range(n):
x,y = map(int,input().split())
a[x-1].append(y)
for i in range(3):
a[i].sort(reverse=True)
a_one_odd = []
a_one_even = []
a_length = [len(a[i]) for i in range(3)]
for i in range(0,a_length[0]-1,2):
a_one_even.append(a[0][i]+a[0][i+1])
fo... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 111111;
long long dp[4][maxn];
int cnt[4];
long long go(int x, int y) { return dp[2][x] + dp[1][min(cnt[1], y - x * 2)]; }
long long get(int x) {
int l = 0, ans = min(x >> 1, cnt[2]), r = ans - 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (go(... | 11 | CPP |
#include <bits/stdc++.h>
namespace OI {
template <class T>
void rd(T &x) {
x = 0;
int f = 1;
char c;
while (!isdigit(c = getchar()))
if (c == '-') f = -1;
do {
x = (x << 3) + (x << 1) + (c ^ 48);
} while (isdigit(c = getchar()));
x *= f;
}
template <class T>
void pt(T x) {
if (x < 0) putchar('-'... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long calc(vector<vector<long long> > v, int m, long long res) {
for (int i = 1; i <= 3; ++i) {
sort(v[i].begin(), v[i].end());
reverse(v[i].begin(), v[i].end());
if (i == 1) {
for (int i = 0; i + 1 < v[1].size(); i += 2)
v[2].push_back(v[1][... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
template <typename T1, typename T2, typename T3>
struct query {
T1 ss;
T2 x;
T3 y;
};
template <typename T1, typename T2, typename T3>
bool operator<(query<T1, T2, T3>& o1, query<T1... | 11 | CPP |
def souvenier_calc(max_weight, weights, value):
const = len(weights)
ans = [-1061109567 for x in range(max_weight+1)]
node = [(x, y) for x, y in zip(weights, value)]
node = sorted(node, key=lambda x: x[1]/x[0], reverse=True)
weights = [x[0] for x in node]
value = [x[1] for x in node]
sum = 0... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<long long> a[4];
struct node {
int i, j;
long long c;
node() : c(0){};
node(int i, int j, long long c) : i(i), j(j), c(c){};
bool operator<(const node& x) const { return c < x.c; }
} dp[3 * maxn];
int main() {
ios_base::sync_with... | 11 | CPP |
import sys
from itertools import accumulate
def solve():
n, m = map(int, input().split())
w = [[] for i in range(3)]
for i in range(n):
wi, ci = map(int, sys.stdin.readline().split())
wi -= 1
w[wi].append(ci)
for i in range(3):
w[i].sort(reverse=True)
dp = [0]*(m ... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
int a[MAXN], b[MAXN], c[MAXN], an = 0, bn = 0, cn = 0;
long long sa[MAXN], sb[MAXN], sc[MAXN], dp[MAXN];
bool cmp(int a, int b) { return a > b; }
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
int w, x;
s... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int dp[1000005];
long long int p1[1000005];
long long int p2[1000005];
vector<long long int> v[5];
int main() {
long long int n, m;
scanf("%lld%lld", &n, &m);
for (long long int i = 1; i <= n; i++) {
long long int w, c;
scanf("%lld%lld", &w, &c);
... | 11 | CPP |
n, m = list(map(int, input().split()))
a = [[], [], []]
for i in range(n):
w, c = list(map(int, input().split()))
a[w-1].append(c)
p = [[0], [0], [0]]
for i in range(3):
a[i].sort(reverse=True)
for x in a[i]:
p[i].append(p[i][-1] + x)
ans = 0
for i in range(min(m//3, len(a[2])) + 1):
w = m -... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300003;
int n, m;
long long bestOne[N];
long long bestTwo[N];
long long bestThree[N];
pair<long long, pair<int, int> > bestOneTwo[N];
int main() {
int x, y;
scanf("%d%d", &n, &m);
vector<pair<int, int> > vec;
vector<int> currOne, currTwo, currThree, le... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct NODE {
long long val, x, y;
} dp[100010 * 3];
int cnt[4];
long long pre_sum[4][100010], a[4][100010], ans;
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a, b) * b);
}
template <class T>
inline T bigmod(T p, T e, T M) {
if (e == 0) retur... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long cost[4][300100];
vector<long long> val[4];
long long cal(long long x) {
long long sz = val[2].size();
long long l = 1, r = min(x / 2, sz), best = 0;
while (l <= r) {
long long mid = (l + r) / 2;
if (cost[2][mid * 2] + cost[1][x - mid * 2] >=
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 300010;
struct {
ll v;
ll c1, c2;
} dp[N];
int num[4], n, m;
ll a[4][N], s[4][N];
int main() {
scanf("%d%d", &n, &m);
memset(num, 0, sizeof num);
memset(dp, 0, sizeof dp);
for (int i = 1; i <= n; ++i) {
ll w, c;
scanf(... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
struct data {
ll cost;
int cnt1, cnt2, cnt3;
} d[300010];
ll m, c1[100010], c2[100010], c3[100010], t1 = 0, t2 = 0, t3 = 0;
bool cmp(ll a, ll b) { return a > b; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, M, m, k;
long long now, ans, f_min[25], f_max[25];
struct ff {
long long w, p;
bool operator<(const ff b) const {
return ((long long)b.p * w < (long long)p * b.w) ||
((long long)b.p * w == (long long)p * b.w && w < b.w);
}
} a[100005];
int read()... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int n, m;
vector<long long int> a[4];
vector<double> b[4];
pair<long long int, pair<int, int> > a1[300010];
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
long long int k, l;
cin >> k >> l;
a[k].push_back(l);
}
for (int i = 1; i < 4;... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17L;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int Mod = 1e9 + 7;
struct Souvenirs {
int w, c;
bool friend operator<(Souvenirs x, Souvenirs y) {
return ((double)x.c / x.w) > ((double)y.c / y.w);
}
} a[maxn];
int n, m;
long... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long n, m;
vector<long long> w[3];
long long f(long mid, long tot) {
if (2 * mid > tot) return -(1 >> 30);
if (mid < w[1].size() && (tot - 2 * mid) < w[0].size())
return w[1][mid] + w[0][tot - 2 * mid];
else if (mid < w[1].size())
return w[1][mid] + w[0][w[0].... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long w[200009], c[200009], pre[10][200009];
vector<long long> v[10];
inline bool check(int mid, int curr1, int curr2) {
if (v[1][curr1 - 2 * (mid - 1) - 1] + v[1][curr1 - 2 * (mid - 1) - 2] <=
v[2][curr2 + (mid - 1)]) {
return true;
}
return f... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const int N = 3e5 + 7;
struct node {
int w, c;
double v;
node() {}
node(int w, int c) : w(w), c(c) { v = (double)c / w; }
bool operator<(const node &rhs) const { return... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct nr {
int w, val;
} v[100005];
int cmp(nr a, nr b) { return 1LL * a.val * b.w > 1ll * b.val * a.w; }
long long dp[300005];
int main() {
int n, m, curw = 0, i, j;
long long rasp = 0;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) scanf("%d%d", &v[i].w, &v[i]... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
long long a[MAXN], b[MAXN], c[MAXN];
long long va[MAXN], vb[MAXN], vc[MAXN];
int n, m, indxa = 1, indxb = 1, indxc = 1;
bool cmp(long long a, long long b) { return a > b; }
void get_v(void) {
for (int i = 1; i <= m; i++) {
va[i] = va[i - 1] ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300200;
struct Node {
int a, b;
long long v;
} dp[maxn];
long long n, w, a[4][maxn], sum[maxn];
int a1, b1, c1;
int main() {
int x;
long long y;
scanf("%lld%lld", &n, &w);
a1 = b1 = c1 = 0;
for (int i = 0; i < n; i++) {
scanf("%d%lld", &x,... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = (2e5 + 5);
const long long MOD = 10243;
const long long INF = 1e16;
const long long LOG = 29;
long long binpow(long long a, long long b) {
a %= MOD;
long long res = 1;
while (b > 0) {
if (b & 1) res = (res * a) % MOD;
a = (a * a) % MOD;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-9;
const int maxV = 3e5 + 5;
int n, V, mV, a[maxV], tot;
long long dp[5][maxV];
vector<long long> w[5];
void solve(int l, int r, int L, int R, int id) {
... | 11 | 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 = 100000;
const int MAXCAP = 300000;
typedef struct R {
int w, c;
} R;
bool operator<(const R &a, const R &b) {
return (long long)a.c * b.w > (long long)b.c * a.w;
}
int n, cap... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct Souvenir {
int w, c;
bool operator<(const Souvenir &ot) const {
if (ot.w == w) return c > ot.c;
return w < ot.w;
}
} s[100002];
int cnt[3];
long long sum[3][100002];
long long ans;
long long cost(int i, int w) {
return sum[1][i] + sum[0][min... | 11 | CPP |
import sys
n, m = map(int, input().split())
w1 = []
w2 = []
w3 = [10**10]
for w, c in (map(int, l.split()) for l in sys.stdin):
if w == 1:
w1.append(c)
elif w == 2:
w2.append(c)
else:
w3.append(c)
w1.sort(reverse=True)
w2.sort(reverse=True)
w3.sort(reverse=True)
w3[0] = 0
w1_size, ... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
typedef struct status {
long long val;
long long cnt1;
long long cnt2;
} status;
vector<long long> v[4];
status s[300001];
int main() {
int n, m, w;
long long c, ans, add;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d%I64d", &w, &c);
v... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
vector<long long> a3, a2, a1;
for (int i = 0; i < n; i++) {
long long w, c;
cin >> w >> c;
if (w == 3)
a3.push_back(c);
else if (w == 2)
a2.push_back(c);
else
a1.push_back(c);
}
so... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long ans, dp[N];
int ed, n, m;
struct node {
int w, c;
double val;
node(int a = 0, int b = 0) : w(a), c(b) {}
bool operator<(const node &b) const { return val > b.val; }
} a[N], tmp[N];
long long DP() {
for (int i = 1; i <= ed; i++) {
... | 11 | CPP |
#include <bits/stdc++.h>
void debug() {}
const int N = 1e5 + 5;
long long n, m, dp[N * 5];
struct Node {
long long weight, cost, ratio;
bool operator<(const Node &rhs) const { return ratio > rhs.ratio; }
} A[N];
int main() {
scanf("%lld %lld", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%lld %lld", &A[i]... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long take[4][N];
long long best[4][N];
int cnt[N];
int n, m;
long long solve(int weight, int take_dua) {
int one = min(cnt[1], weight - 2 * take_dua);
return take[2][take_dua] + take[1][one];
}
int main() {
scanf("%d %d", &n, &m);
for (in... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<long long> A, B, C;
vector<long long> b, c, bb, cc;
long long solve(int mm) {
b.push_back(0);
bb.resize(b.size());
bb[0] = b[0];
for (int i = 1; i < (int)b.size(); i++) bb[i] = b[i] + bb[i - 1];
cc.resize(c.size());
cc[0] = c[0];
for (int i = ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long mode(long long a) {
a %= mod;
if (a < 0) a += mod;
return a;
}
long long subt(long long a, long long b) { return mode(mode(a) - mode(b)); }
long long add(long long a, long long b) { return mode(mode(a) + mode(b)); }
long long mult(lo... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef struct {
long long int cost, ones, twos;
} s;
int main() {
long long int n, m;
cin >> n >> m;
vector<long long int> ones;
vector<long long int> twos;
vector<long long int> threes;
for (long long int i = 0; i < n; i++) {
long long int a, b;
cin ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int qq = 3e5 + 10;
struct Backpack {
long long val;
int m1, m2;
} dp[qq];
int num[4];
long long Val[4][qq];
long long pre[4][qq];
int n, m;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
int w;
long long val;
scanf("%d%lld", &w,... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long dp[300024];
int k[300024][3];
vector<int> v[3];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int w, c;
cin >> w >> c;
v[w - 1].push_back(c);
}
for (int i = 0; i < 3; i++) {
sort(v[i].begin(), v[i].end());
revers... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
vector<LL> sum[4];
LL check(int two, int three, int rem) {
LL rv = 0;
if (two > 0) rv += sum[2][two - 1];
if (three > 0) rv += sum[3][three - 1];
int one = rem - two * 2 - three * 3;
assert(one >= 0);
one = min(on... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000 + 10;
const int INF = 0x7fffffff;
struct {
long long v;
long long s1, s2;
} dp[MAXN];
long long a[4][MAXN];
long long s[4][MAXN];
int num[4];
int cmp(int x, int y) { return x > y; }
int main() {
int n, m;
scanf("%d%d", &n, &m);
num[1] = num... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
struct nod {
long long val, pt1, pt2;
} dp[300005];
ifstream in("selling.in");
vector<long long> unu, doi, trei;
nod Max(nod a, nod b) { return a.val < b.val ? b : a; }
int main() {
long long i, j, w, v, last1, last2, var1, var2;
cin >> n >> m;
for (... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v(3);
long long s[3][100005];
int m;
long long f1(int y, int z) {
if (m - 3 * z - 2 * y < 0) {
return 0;
}
long long val = 0;
if (z > 0) val += s[2][z - 1];
if (y > 0) val = val + s[1][y - 1];
if (m - 3 * z - 2 * y > 0) {
val += s[0]... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mod = 1e9 + 7;
long long kek[100005], w[100005], dp[1337228], c[100005], nm[100005];
bool kekekekekekkek(int i, int j) { return kek[i] > kek[j]; }
int main() {
ios_base::sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = ... | 11 | CPP |
#!/usr/bin/env python3
[n, m] = map(int, input().strip().split())
wc = [[] for _ in range(4)] # w[0] unused
for _ in range(n):
w, c = map(int, input().strip().split())
wc[w].append(c)
for i in range(1, 4):
wc[i].sort(reverse=True)
iwc = [[0 for _ in range(len(wc[i]) + 1)] for i in range(4)]
for i in range(4):
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct Data {
long long cost, ones, twos;
};
const long long N = 100100;
const long long K = 300300;
long long n, m;
Data dp[K];
vector<long long> adj[4];
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (long long i = 1; i <... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int n, m;
int arr[4][N];
int idx[4];
long long best[N], ans = 0;
pair<int, int> best2[N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
int w, c;
scanf("%d%d", &w, &c);
arr[w][idx[w]++] = c;
}
for (int i = 0; i <... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, w;
long long c, r, vop;
vector<long long> s[3], op[2], tot[3];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d %lld", &w, &c);
s[w - 1].push_back(c);
}
sort(s[2].begin(), s[2].end());
tot[0].push_back(0);
for (int i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long dp[300005];
struct S {
int w, c;
bool friend operator<(S x, S y) {
return ((double)x.c / x.w > (double)y.c / y.w);
}
} a[100005];
int main() {
while (scanf("%d%d", &n, &m) != -1) {
for (int i = 1; i <= n; i += 1) {
scanf("%d%d", &a[... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int MAXW = 300010;
int n, m;
int a[MAXW] = {0}, b[MAXW] = {0}, c[MAXW] = {0};
int aidx = 0, bidx = 0, cidx = 0;
long long f[MAXW] = {0};
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
int w, cost;
scanf("%d%d", &... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, m, sum;
long long ans, pre[4][N];
vector<int> a[4];
long long check(int mid, int have) {
int one = have - 3 * mid;
if (one > a[1].size()) one = a[1].size();
return pre[3][mid] + pre[1][one];
}
long long del(int have) {
int l = 0, r = a[... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
unsigned sed = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 rand_num(sed);
uniform_int_distribution<long long> dis(0, 1000000007);
template <typename T>
void read(T &x) {
x = 0;
char ch = getchar();
long long fh = 1;
while (ch < '0' || ch > '... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
pair<long long int, pair<int, int> > dp[300005];
vector<int> cost1;
vector<int> cost2;
vector<int> cost3;
int main() {
int n, m;
cin >> n;
cin >> m;
for (int i = 0; i < n; i++) {
int w, c;
cin >> w;
cin >> c;
if (w == 1) {
cost1.push_back(c);
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, i, l1, l2, l3;
long long pre[311111], ans;
long long dp[311111][3];
vector<long long> v[3];
bool cmp(long long x, long long y) { return x > y; }
long long min(long long x, long long y) { return x < y ? x : y; }
long long max(long long x, long long y) { retur... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
re... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
void solve(std::istream& in, std::ostream& out) {
long long n, m;
in >> n >> m;
std::array<std::vector<long long>, 3> c, c_sum;
for (long long i = 0; i < n; ++i) {
long long w, cur_c;
in >> w >> cur_c;
c[w - 1].p... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long r;
bool is_perfect_cube(long long n) {
r = (long long)round(cbrt(n));
if (r * r * r == n) return true;
return false;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
int a, b;
scanf("%d %d", &a, &b);
if (is_perfect_cube((long long)a * b... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
while (n--) {
long long x, y, z, w;
scanf("%I64d%I64d", &x, &y);
z = x * y;
w = pow(z, 1.0 / 3) + 0.5;
if (w * w * w == z && x % w == 0 && y % w == 0)
puts("Yes");
else
puts("No");
}
return 0... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int vec[1000005];
map<long long, int> M;
int main() {
int n;
cin >> n;
for (int i = 2; i <= 1000000; i++) {
if (vec[i]) continue;
for (int j = i; j <= 1000000; j += i) vec[j] = i;
}
for (int i = 1; i <= 1000000; i++) {
M[1LL * i * i * i] = i;
}
for... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long M = (long long)1e9 + 7;
int Int() {
int x;
scanf("%d", &x);
return x;
}
long long Long() {
long long x;
scanf("%lld", &x);
return x;
}
void Char(char *ch) { scanf("%s", ch); }
template <typename t>
inline t abs(t a) {
if ... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
void testCase() {
int64_t a, b;
cin >> a >> b;
int64_t crt = cbrtl(a * b);
int64_t have = crt * crt * crt;
if ((have == (a * b)) && a % crt == 0 && b % crt == 0) {
cout << "YES" << '\n';
} else {
cout << "NO" << '\n';
}
}
signed main() {
ios_base::sy... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long cubeRoot(long long n) {
long long l = 0, r = 1001010, m;
while (l != r) {
m = (l + r + 1) / 2;
if (m * m * m > n) {
r = m - 1;
} else {
l = m;
}
}
return l;
}
int main() {
long long c, a, b, n, i, j, k, flag = 0, x, sum = 0, s... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<long long, int> mp;
for (long long i = 1; i <= 1e6; ++i) mp[i * i * i] = i;
int t;
cin >> t;
while (t--) {
long long a, b;
scanf("%lld %lld", &a, &b);
if (mp.count(a * b) and a % mp[a * b] == 0 and b % mp[a * b] == 0)
printf("YeS... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
long long a, b;
scanf("%lld%lld", &a, &b);
long long l = 1, r = 1000000, x = -1;
while (l <= r) {
long long mid = (l + r) / 2;
if (mid * mid * mid > a * b)
r = mid - 1;
else if (mid ... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int e = 2 * 1e6 + 7;
long long a[e];
long long bs(long long x) {
long long l = 0, h = 1000005;
while (l != h) {
long long m = (l + h + 1) / 2;
if (m * m * m > x) {
h = m - 1;
} else {
l = m;
}
}
return l;
}
int main() {
int t;
c... | 7 | CPP |
import sys,os,io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left , bisect_right
import math
def ii():
return int(input())
def li():
return list(map(int,input().split()))
if(os.p... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int N;
int gcd(int x, int y) {
while (y) {
x %= y;
swap(x, y);
}
return x;
}
int cube(int x) { return x * x * x; }
int iscube(int x) {
int y = 0;
for (int l = 10; l >= 0; l--) {
if (cube(y + (1 << l)) <= x) {
y += 1 << l;
}
}
return cube(... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long check(long long p) { return p * p * p; }
long long res;
bool binary_search(long long l, long long r, long long q) {
long long mid = (l + r) / 2;
while (l <= r) {
mid = (l + r) / 2;
long long c = check(mid);
if (c > q) {
r = mid - 1;
} els... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
long long cube(long long c) {
long long l = 1, r = 1e6, mid;
while (l < r) {
mid = (l + r) / 2;
if ((mid * mid * mid) < c)
l = mid + 1;
else
r = mid;
}
return l;
}
int main() {
int n;
scanf("%d",... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
ll a, b;
cin >> a >> b;
ll x = round(pow(a * b, 1.0 / 3.0));
if (pow(x, 3) == a * b && a % x == 0 && b % x == 0)
cout << "YES\n";
... | 7 | CPP |
#include <bits/stdc++.h>
#pragma 03
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization("unroll-loops")
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
while (t--) {
long long a,... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int T;
long long a, b, x;
int Calc(int x, int a) {
int cnt = 0;
for (; a % x == 0; a /= x, cnt++)
;
return cnt;
}
bool judge(int x, int a, int b) {
int p = Calc(x, a), q = Calc(x, b);
return p + p >= q && q + q >= p;
}
int main() {
for (cin >> T; T--;) {
... | 7 | CPP |
import sys
input = sys.stdin.readline
print = sys.stdout.write
cbrt = {i**3:i for i in range(1001)}
n = int(input())
all_res = []
for _ in range(n):
a, b = map(int, input().split())
if a == b:
all_res.append('Yes' if a in cbrt else 'No')
continue
if a > b:
a, b = b, a
r = cbrt.... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9 + 7;
const long long int modc = 998244353;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
while (n--) {
long long int a, b;
cin >> a >> b;
long long int prod = a * b,... | 7 | CPP |
#include <bits/stdc++.h>
const int maxh = 1e5 + 10, maxn = 350010;
using namespace std;
long long n, m, k, ps, pr[maxh];
vector<long long> p;
map<pair<int, int>, int> mp;
void sieve() {
for (long long i = 2; i < maxh; i++) {
if (pr[i]) continue;
p.push_back(i);
for (long long j = i * i; j < maxh; j += i) ... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
map<long long, int> mp;
for (long long i = 1; i <= 1e6; ++i) mp[i * i * i] = i;
int t;
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
if (mp.count(a * b) and a % mp[a * b] == 0 a... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int Cube_Root(long long int x) {
long long int l = 1, r = 1000005;
while (l < r) {
long long int mid = (l + r) / 2;
if (mid * mid * mid >= x) {
r = mid;
} else {
l = mid + 1;
}
}
if (l * l * l > x) {
return l - 1;
} else {... | 7 | CPP |
#include <bits/stdc++.h>
int main() {
int T;
scanf("%d", &T);
while (T--) {
long long a, b;
scanf("%I64d%I64d", &a, &b);
long long tmp = ceil(cbrt(a * b));
puts(tmp * tmp * tmp == a * b && a % tmp == 0 && b % tmp == 0 ? "Yes"
: "No"... | 7 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.