Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
using namespace std; typedef long long ll; int main() { int N, W; cin >> N >> W; vector
val(N), wt(N); for(int i = 0; i < N; i++) { cin >> val[i] >> wt[i]; } vector
dp(W + 5, -2e9); dp[W] = 0; for(int weight = W; weight >= 0; weight--) { for(int i = 0; i < N; i++) { if(weight - wt[i] >= 0) { dp[weight - wt[i]] = max(dp[weight - wt[i]], dp[weight] + val[i]); } } } int result = -2e9; for(int i = 0; i <= W; i++) { result = max(result, dp[i]); } if(result == -2e9) result = 0; cout << result << endl; return 0; } /* 3 8 3 30 4 50 5 60 140: 12 139 = inf 138 = inf 110: 9 90: 8 80: 7 60: 5 50: 4 30: 3 */
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)