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
using namespace std; #define ll long long #define pb push_back #define mp make_pair int n, c; vector
> weight; int dp[100][30000]; int rec(int idx, int w){ if(idx == c) return 0; if(dp[idx][w] != -1){ return dp[idx][w]; } int result = -2e9; result = max(result, rec(idx + 1, w)); if(weight[idx].second <= w){ result = max(result, rec(idx + 1, w - weight[idx].second + weight[idx].first) + 1); } dp[idx][w] = result; return result; } int main(){ ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> n >> c; for(int i = 0; i < c; i++){ int a, b; cin >> a >> b; weight.pb(mp(b, a)); } sort(weight.rbegin(), weight.rend()); for(int i = 0; i < c; i++){ for(int j = 0; j < 30000; j++){ dp[i][j] = -1; } } cout << rec(0, n) << endl; return 0; }
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)