voidsolve(){ int n = read(); std::vector<int> a(n); for(auto& x : a) x = read(); std::sort(a.rbegin(), a.rend()); ll ans = 0; for(int i = 0; i < n; ++i){ if(i % 3 == 2) continue; ans += a[i]; } printf("%lld\n", ans); }
B. Wash
题意:
有() 件衣服,() 台洗衣机,() 台烘干机。
第台洗衣机洗衣要分钟,第台烘干机烘干要分钟。
每件衣服都要先洗后烘,求最少需要多少分钟。
首先肯定要贪心,用小根堆分别模拟洗衣和烘干的过程,求出有序的洗衣完成时间,以及烘干完成时间。
接下来就是两两配对,最小化。
这应该是排序不等式的一个应用吧,用小的配大的,就能让最小。
故答案为。
时间复杂度。
AC Code:
voidsolve(){ int L = read(), n = read(), m = read(); std::vector<ll> w(n), d(m); for(auto& x : w) x = read(); for(auto& x : d) x = read(); std::vector<ll> A(L), B(L);
auto calc = [&](std::vector<ll>& a, std::vector<ll>& res) -> void { // struct X {ll nxt, cost;}; std::priority_queue<std::pair<ll, ll>> q; for(auto t : a) q.push({-t, t}); for(int i = 0; i < L; ++i){ auto x = q.top(); q.pop(); res[i] = -x.first; x.first = -(-x.first + x.second); q.push(x); } }; calc(w, A); calc(d, B); std::reverse(B.begin(), B.end()); ll ans = 0; for(int i = 0; i < L; ++i){ ans = std::max(ans, A[i] + B[i]); } printf("%lld\n", ans); }
D. Game Leader
题意:
Tom 有() 个好友,排名从到,其中 Tom 的排名是。除 Tom 外每个好于都有自己的好友榜单(有 Tom 不认识的陌生人),在除 Tom 以外的个好友榜单中,排名为的人的霸榜次数为。
Tom 已知() 条好友关系,求在满足这些已知好友关系和上面的的情况下,最少有多少个陌生人的榜单被 Tom 的好友霸榜。
ll query(int p, int L, int R){ if(t[p].l >= L and t[p].r <= R) return t[p].val; pushdown(p); // byd 忘记 pushdown 调半天 int mid = (t[p].l + t[p].r) >> 1; ll res = 2e18; if(L <= mid) res = std::min(res, query(p << 1, L, R)); if(R > mid) res = std::min(res, query(p << 1 | 1, L, R)); return res; } };
voidsolve(){ int n = read(), m = read(); std::vector<std::pair<int, int>> a(n); for(auto& [l, r] : a) l = read(), r = read(); std::sort(a.begin(), a.end()); std::vector<int> C(m); for(int i = 0; i < m; ++i) C[i] = read(); std::sort(C.begin(), C.end()); SGT sgt(n); sgt.build(1, 1, m); ll Q = 2e18; int p = 0;
for(int i = 0; i < m; ++i){ // 将所有左端点 <= C[i] 的问题计入贡献 while(p < n and a[p].first <= C[i]){ int R = a[p].second; int pos = std::upper_bound(C.begin(), C.end(), R) - C.begin(); // 1-based sgt, pos 不用减一 if(pos > 0) sgt.add(1, 1, pos, 1); ++p; } // 1-based sgt, i 要加一 ll val = sgt.query(1, 1, i + 1); // i 是 0-based,需要加一 Q = std::min(Q, val - (i + 1) - 1); }
if(Q < 0) returnputs("IMPOSSIBLE!"), void(); printf("%lld\n", n - Q); }
voidsolve(){ int n = read(), m = read(); std::vector<std::vector<int>> C(n), D(m); for(int i = 0; i < n; ++i){ int c = read(); C[i] = std::vector<int>(c); for(auto& x : C[i]) x = read(); } for(int i = 0; i < m; ++i){ int d = read(); D[i] = std::vector<int>(d); for(auto& x : D[i]) x = read(); }
auto check = [&](int id, int mask) -> bool { for(auto& need : C[id]){ bool ok = false; for(int i = 0; i < m and !ok; ++i){ if((mask >> i) & 1){ for(auto& skill : D[i]){ if(skill == need){ ok = true; break; } } } } if(!ok) returnfalse; } returntrue; };
voidsolve(){ int Y, M, D, h, m, s; scanf("%d-%d-%d %d:%d:%d", &Y, &M, &D, &h, &m, &s); if(M == 1or M == 2or M == 12) returnputs("PST"), void(); if(M >= 4and M <= 10) returnputs("PDT"), void();
auto get = [&](int y, int m, int n) -> int { tm t = {0}; t.tm_year = y - 1900; t.tm_mon = m - 1; t.tm_mday = 1; mktime(&t);