版本比较
SnackOI R1-D 战争与和平 题解
正文
增加 9 行删除 9 行
32 行未改动33343536373839404116 行未改动58596061626364656667686970717273747576777879808182838485868788899091929394959697989910010132 行未改动代码献上。```cpp#include <bits/stdc++.h>using u32 = unsigned;using i64 = long long;using u64 = unsigned long long;16 行未改动int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);std::cin >> n >> l >> r;for (int i = 1; i <= n; ++i) {std::cin >> a[i];}std::sort(a + 1, a + n + 1);for (int i = 1; i <= n; ++i) {sum[i] = sum[i - 1] + a[i];}h = 1, t = 0;if (1 - r <= 0 && 0 <= 1 - l) {q[++t] = 0;}for (int i = 1; i <= n; ++i) {while (h <= t && q[h] < i - r) {++h;}if (h <= t) {int j = q[h];dp[i] = f(j) + sum[i] - a[i];} else {dp[i] = -INF;}int id = i - l + 1;if (id >= 0) {while (h <= t && f(q[t]) <= f(id)) {--t;}q[++t] = id;}}std::cout << dp[n];return 0;}```32 行未改动33343536373839404116 行未改动58596061626364656667686970717273747576777879808182838485868788899091929394959697989910010132 行未改动代码献上。```cpp#include <bits/stdc++.h>using u32 = unsigned;using i64 = long long;using u64 = unsigned long long;16 行未改动int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);std::cin >> n >> l >> r;for (int i = 1; i <= n; ++i) {std::cin >> a[i];}std::sort(a + 1, a + n + 1);for (int i = 1; i <= n; ++i) {sum[i] = sum[i - 1] + a[i];}h = 1, t = 0;if (1 - r <= 0 && 0 <= 1 - l) {q[++t] = 0;}for (int i = 1; i <= n; ++i) {while (h <= t && q[h] < i - r) {++h;}if (h <= t) {int j = q[h];dp[i] = f(j) + sum[i] - a[i];} else {dp[i] = -INF;}int id = i - l + 1;if (id >= 0) {while (h <= t && f(q[t]) <= f(id)) {--t;}q[++t] = id;}}std::cout << dp[n];return 0;}```