Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
33101 | 林芳菲 | 【J】T3 | C++ | 运行超时 | 50 | 1000 MS | 1424 KB | 680 | 2024-10-04 14:17:07 |
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; int n, q, b[100010]; long long f[100010]; long long dfs(int x, int y) { if (x <= y) return f[x] = 0; if (f[x] != 9e18) return f[x]; for (int i = 2; i <= n; i++) f[x] = min(f[x], dfs(x / i, y) + b[i]); return f[x]; } int main() { scanf("%d %d", &n, &q); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); while (q--) { int x, y; scanf("%d %d", &x, &y); for (int i = 0; i <= x; i++) f[i] = 9e18; printf("%lld\n", dfs(x, y)); } return 0; }