1 条题解
-
0
自动搬运
来自洛谷,原作者为

Alex_Wei
**搬运于
2025-08-24 21:49:57,当前版本为作者最后更新于2021-12-19 22:33:57,作者可能在搬运后再次修改,您可在原文处查看最新版自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多
以下是正文
注意到对于一个固定的 ,我们只关心前 个需求为 的顾客,便可断言接下来需求为 的顾客不可能拿到代金券,这一点显然。
因此,若当前需求为 的顾客数量 ,那么可以跳过剩下来所有这样的顾客。直接暴力模拟,时间复杂度是调和级数求和产生的 ,可以接受。
const int N = 1e6 + 5; int n, m, cnt, buc[N]; ll tot, ans[N], cur[N]; int main(){ cin >> m; for(int i = 1; i <= m; i++) buc[read()] = 1; n = read(); for(int i = 1; i <= n; i++) { int k = read(); if(cur[k] * k >= N) {tot += k; continue;} int rest = k; while(rest) { int p = (++cur[k]) * k; if(p >= N) break; if(buc[p] == 1) ans[++cnt] = tot + k - rest + 1; if(buc[p] >= 0) buc[p] = -1, rest--; } tot += k; } cout << cnt << endl; for(int i = 1; i <= cnt; i++) print(ans[i]), pc('\n'); return 0; }
- 1
信息
- ID
- 2612
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 5
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者