aboutsummaryrefslogtreecommitdiff
path: root/13.5
diff options
context:
space:
mode:
authorAnthony Wang2022-03-15 20:38:51 -0500
committerAnthony Wang2022-03-15 20:38:51 -0500
commit896c6ceeff605c935a5538e3d9eca40ea3c79c56 (patch)
tree69d97b50f5ced801f6043cbef0219a941239f892 /13.5
parent4c488e4c73f2d0e2b96bf0c444c05d42e566dd11 (diff)
Restructure directories AGAIN so contests from the same season are in the same directory
Diffstat (limited to '13.5')
-rw-r--r--13.5/nov/gold/nochange.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/13.5/nov/gold/nochange.cpp b/13.5/nov/gold/nochange.cpp
new file mode 100644
index 0000000..ad34b80
--- /dev/null
+++ b/13.5/nov/gold/nochange.cpp
@@ -0,0 +1,37 @@
+#include <algorithm>
+#include <iostream>
+using namespace std;
+
+int v[20], p[100005] = { 0 }, DP[1 << 16];
+
+inline int sum(int i, int j) { return p[j + 1] - p[i]; }
+
+int main() {
+ int K, N; cin >> K >> N;
+ for (int i = 0; i < K; i++) cin >> v[i];
+ for (int i = 0; i < N; i++) {
+ int c; cin >> c;
+ p[i + 1] = c + p[i];
+ }
+
+ for (int i = 0; i < (1 << K); i++) if (DP[i] < N) {
+ for (int j = 0; j < K; j++) if ((i & 1 << j) == 0) {
+ int l = DP[i], h = N;
+ while (l + 1 < h) {
+ int m = (l + h) / 2;
+ sum(DP[i], m) > v[j] ? h = m : l = m;
+ }
+ DP[i ^ 1 << j] = max(l + 1, DP[i ^ 1 << j]);
+ }
+ }
+
+ int ans = -1;
+ for (int i = 0; i < (1 << K); i++) {
+ if (DP[i] == N) {
+ int sum = 0;
+ for (int j = 0; j < K; j++) if ((i & 1 << j) == 0) sum += v[j];
+ ans = max(sum, ans);
+ }
+ }
+ cout << ans << endl;
+}