#include<cstdio> #include<iostream> #define rei register int #define N 100010 #define mod 10000 usingnamespace std; string s; longlong stack[N], tot, len, num, b, ans; intmain() { cin >> s; len = s.length(); for (rei i = 0; i < len; i++) { if (s[i] >= '0' && s[i] <= '9') num = num * 10 + s[i] - '0'; elseif (s[i] == '+') { if (!b) stack[++tot] = num % mod; else stack[tot] = stack[tot] * num % mod; num = 0; b = 0; } elseif (s[i] == '*') { if (!b) stack[++tot] = num % mod; else stack[tot] = stack[tot] * num % mod; num = 0; b = 1; } if (i + 1 == len) { if (!b) stack[++tot] = num % mod; else stack[tot] = stack[tot] * num % mod; } } for (rei i = 1; i <= tot; i++) ans += stack[i]; printf("%lld\n", ans % mod); return0; }
import sys import heapq from collections import defaultdict
input = sys.stdin.readline
if __name__ == '__main__': n, m, o = map(int, input().split()) tot, ans, res = 0, 10 ** 19, 0 q = []
for i inrange(n): a, b, c = map(int, input().split()) if tot < m: x = min(m - tot, b) heapq.heappush(q, (-a, x)) tot += x res += x * a b -= x if tot >= m: while b: ifnot q: heapq.heappush(q, (-a, min(m, b))) res += a * min(m, b) (x, y) = heapq.heappop(q) x = -x res -= x * y if x <= a: heapq.heappush(q, (-x, y)) res += x * y break else: if y <= b: heapq.heappush(q, (-a, y)) res += a * y b -= y else: heapq.heappush(q, (-x, y - b)) res += x * (y - b) heapq.heappush(q, (-a, b)) res += a * b break ans = min(ans, res + c * o) print(ans if ans != 10 ** 19else -1)
G 廊桥分配
Solution
先单独对国内区进行讨论。建立一个小根堆维护正在被使用的廊桥,关键字是廊桥所属的飞机离开的时间。
注意到廊桥依照先到先得进行分配。
按时间枚举飞机。若当前飞机到达时,堆顶的廊桥依然被占用,且当前共有 n 架廊桥,则该飞机的离开时间标记为第 n+1 号廊桥的解放时间,将廊桥加入堆中。当前飞机用的是 i 号廊桥,则 cnt1i=cnt1i+1。对 cnt1 进行前缀和处理,即可 O(1) 查询给国内分配 k 架廊桥时,有多少飞机能用上廊桥。
intmain() { //freopen("airport.in", "r", stdin); //freopen("airport.out", "w", stdout); read(n); read(ma); read(mb); for (rei i = 1; i <= ma; i++) read(a[i].x), read(a[i].y); for (rei i = 1; i <= mb; i++) read(b[i].x), read(b[i].y); sort(a + 1, a + 1 + ma, cmp); sort(b + 1, b + 1 + mb, cmp); for (rei i = 1; i <= n; i++) Qa.push(-i), Qb.push(-i); for (rei i = 1; i <= ma; i++) { while (!qa.empty()) { if (-qa.top().first <= a[i].x) Qa.push(qa.top().second), qa.pop(); elsebreak; } if (Qa.empty()) continue; int x = Qa.top(); Qa.pop(); qa.push(make_pair(-a[i].y, x)); ++ansa[-x]; } for (rei i = 1; i <= mb; i++) { while (!qb.empty()) { if (-qb.top().first <= b[i].x) Qb.push(qb.top().second), qb.pop(); elsebreak; } if (Qb.empty()) continue; int x = Qb.top(); Qb.pop(); qb.push(make_pair(-b[i].y, x)); ++ansb[-x]; } for (rei i = 1; i <= n; i++) ansa[i] += ansa[i - 1], ansb[i] += ansb[i - 1]; for (rei i = 0; i <= n; i++) ans = max(ans, ansa[i] + ansb[n - i]); printf("%d", ans); return0; }