#include<bits/stdc++.h> #define int long long #define debug usingnamespace std;
constint N = 1e5+66;
int n;
inlineintthestars(){ cin >> n; int l = 1, r = sqrt(n)*2+1; int mo = 2*n-2; while (l < r) { int mid = (l + r)>>1; if (mid*(mid+1) >= mo) r = mid; else l = mid+1; } cout << l; return0; }
#include<bits/stdc++.h> #define int long long #define debug usingnamespace std;
inlinelonglongread(){ longlong s = 0, f = 1; char ch; while(!isdigit(ch = getchar())) (ch == '-') && (f = -f); for(s = ch ^ 48;isdigit(ch = getchar()); s = (s << 1) + (s << 3) + (ch ^ 48)); return s * f; }
constint N = 3e5+66, INF = 214748364000000;
int n, res = INF; int vis[N];
structnode{int a, t, v;}yhm[N];
inlinevoiddfs(int x, int num, int ans, int fangyu){ vis[x] = 1; if (num == n) { res = min(res, ans); return; } for (int i = 1; i <= n; ++ i) { if (!vis[i]) { int now_ans = (yhm[i].a-fangyu)*yhm[i].t+ans; int now_fangyu = yhm[i].v + fangyu; dfs(i, num+1, now_ans, now_fangyu); vis[i] = 0; } } }
inlineintthestars(){ n = read(); for (int i = 1; i <= n; ++ i) yhm[i].a = read(), yhm[i].t = read(), yhm[i].v = read(); for (int i = 1; i <= n; ++ i) { memset (vis, 0, sizeof vis); dfs(i, 1, yhm[i].a*yhm[i].t, yhm[i].v); } cout << res; return0; }
#include<bits/stdc++.h> #define LL long long #define debug usingnamespace std;
constint N = 1e5+66;
int n, m; LL L, res; int a[N];
inlineintpd(int x){ intan(0), last(0); for (int i = 1; i <= n+1; ++ i) (a[i]-last<x)? ++ an : last = a[i]; // printf("pd %d = %d\n", x, m >= an); return m>=an; }
inlineintthestars(){ cin >> L >> n >> m; for (int i = 1; i <= n; ++ i) cin >> a[i]; a[n + 1] = L; LL l = 1, r = L; while (l < r) { LL mid = (l+r+1)>>1; if (pd(mid)) l = mid; else r = mid - 1; } cout << l; return0; }
#include<bits/stdc++.h> #define int long long #define debug usingnamespace std;
constint N = 1e5+66, inf = 600000000;
int n, m; int a[N];
inlineintpd(int x){ intan(0); for (int i = 0; i <= n; ++ i) an += max(x - a[i], 0ll); return x>=an; }
inlineintthestars(){ cin >> n >> a[0]; for (int i = 1; i <= n; ++ i) cin >> a[i]; int l = 0, r = inf; while (l < r) { int mid = (l+r+1)>>1; if(pd(mid)) l = mid; else r = mid - 1; } cout << l; return0; }
#include<bits/stdc++.h> #define LL long long #define debug usingnamespace std;
constint N = 1e5+66; constdouble eps = 1e-6;
int n, t; int d[N]; double s[N];
inlineintthestars(){ while (scanf ("%d%d", &n, &t) != EOF) { int cnt = 100, i; double l = 1e8, r = 1e8, res, mid; for (i = 1; i <= n; ++ i) { cin >> d[i] >> s[i]; l = min(l, s[i]); } l = -l; while (cnt --) { mid = (l+r)/2, res = 0; for (int i = 1; i <= n; ++ i) res += d[i]/(s[i]+mid); if (res < t) r = mid; else l = mid; } printf ("%.9lf\n", l); } return0; }
inlineintthestars(){ scanf ("%d", &n); for (int i = 1; i <= n; ++ i) scanf ("%d%d", &a[i].s, &a[i].t); sort(a + 1, a + n + 1, cmp); int end = a[1].t; res = 1; for (int i = 2; i <= n; ++ i) { if (end <= a[i].s) { ++ res, end = a[i].t; } } cout << res; return0; }
#include<bits/stdc++.h> #define int long long #define debug usingnamespace std;
constint N = 3e5+66;
int n, num; int a[N], b[N], v[N];
priority_queue<pair<int, int> >q;
inlineintthestars(){ scanf ("%lld", &n); for (int i = 1; i <= n; ++ i) scanf ("%lld", &a[i]); for (int i = 1; i <= n; ++ i) scanf ("%lld", &b[i]); int res = 0; for (int i = 1; i <= n; ++ i) { res += a[i]; if (res >= b[i]) { res -= b[i]; q.push(make_pair(b[i], i)); v[i] = 1; } else { if (!q.empty() && q.top().first > b[i]) { int t = q.top().second; q.pop(); res = res + b[t] - b[i]; q.push(make_pair(b[i], i)); v[t] = 0, v[i] = 1; } } } for (int i = 1; i <= n; ++ i) if (v[i]) ++ num; printf ("%lld\n", num); for (int i = 1; i <= n; ++ i) if (v[i]) cout << i << ' '; return0; }
#include<bits/stdc++.h> #define int long long #define debug usingnamespace std;
constint N = 1e7+66;
queue<int>q1, q2;
int n, res; int a[N], b[N>>6];
inlineintread(){ int x = 0, f = 1; char ch; while (! isdigit(ch = getchar())) (ch == '-') && (f = -f); for (x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48)); return x * f; }
inlineintFind(){ int x; if ((q1.front() < q2.front() && !q1.empty()) || q2.empty()) { x = q1.front(); q1.pop(); } else { x = q2.front(); q2.pop(); } return x; }
inlineintthestars(){ n = read(); for (int i = 1; i <= n; ++ i) { a[i] = read(); ++ b[a[i]]; } for (int i = 1; i <= N>>6; ++ i) { while (b[i]) { -- b[i]; q1.push(i); } } for (int i = 1; i < n; ++ i) { int x = Find(); int y = Find(); q2.push(x + y); res += x + y; } cout << res; return0; }
#include<bits/stdc++.h> #define LL long long #define debug usingnamespace std; //东方之珠 整夜未眠! constint N = 1e5+66;
int n, m; pair<string, int>a[N];
inlineintcalc(int bit, int now){ for (int i = 1; i <= n; ++ i) { int x = (a[i].second>>bit)&1; if (a[i].first == "AND") now &= x; elseif (a[i].first == "OR") now |= x; else now ^= x; } return now; }
inlineintthestars(){ cin >> n >> m; for (int i = 1; i <= n; ++ i) { char ch[5]; int x; scanf ("%s%d", ch, &x); a[i] = make_pair(ch, x); } int val = 0, ans = 0; for (int bit = 30; bit >= 0; -- bit) { int res0 = calc(bit, 0); int res1 = calc(bit, 1); if (val + (1<<bit) <= m && res0 < res1) val += (1<<bit), ans += res1 << bit; else ans += res0 << bit; } cout << ans; return0; }