結果
問題 | No.2741 Balanced Choice |
ユーザー |
![]() |
提出日時 | 2024-05-01 10:39:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 1,301 bytes |
コンパイル時間 | 797 ms |
コンパイル使用メモリ | 56,620 KB |
最終ジャッジ日時 | 2025-02-21 09:59:16 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:33:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | scanf("%d%d%d", &n, &w, &d); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:38:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 38 | scanf("%d%d%d", &ti, &wi, &vi); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-** 2741.cc: No.2741 Balanced Choice - yukicoder*/#include<cstdio>#include<vector>#include<algorithm>using namespace std;/* constant */const int MAX_N = 5000;const int MAX_W = 5000;/* typedef */typedef vector<int> vi;/* global variables */int dp[2][MAX_W + 1];/* subroutines */inline void setmax(int &a, int b) { if (a < b) a = b; }/* main */int main() {int n, w, d;scanf("%d%d%d", &n, &w, &d);vi wvs[2], vvs[2];for (int i = 0; i < n; i++) {int ti, wi, vi;scanf("%d%d%d", &ti, &wi, &vi);wvs[ti].push_back(wi);vvs[ti].push_back(vi);}for (int t = 0; t < 2; t++) {fill(dp[t], dp[t] + w + 1, -1);dp[t][0] = 0;for (int i = 0; i < wvs[t].size(); i++) {int wti = wvs[t][i], vti = vvs[t][i];for (int j = w - wti; j >= 0; j--)if (dp[t][j] >= 0) setmax(dp[t][j + wti], dp[t][j] + vti);}//for (int j = 0; j <= w; j++) printf(" %d", dp[t][j]); putchar('\n');}int maxv = 0;for (int i = 0; i <= w; i++)for (int j = max(0, i - d); i + j <= w && j <= i + d; j++)if (dp[0][i] >= 0 && dp[1][j] >= 0) {//printf(" dp[0][%d]=%d, dp[1][%d]=%d\n", i, dp[0][i], j, dp[1][j]);setmax(maxv, dp[0][i] + dp[1][j]);}printf("%d\n", maxv);return 0;}