#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <climits>
#include <cfloat>
#include <cctype>
#include <cstdarg>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <bitset>
#include <vector>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <iterator>
#include <string>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <limits>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <complex>
using namespace std;
#define f1(n) for(int i=0;i<n;i++)
#define e '\n'
#define f2(m,n,q) for(int i=m;i<n;i+=q)
#define f3(n) for(int j=0;j<n;j++)
#define f4(m,n,q) for(int j=m;j<n;j+=q)
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define pb push_back
typedef long long ll;
const int N=2e3+1;
const int mod=998244353;
const int inf=1e18,sqr=448;
vector<int>adj[N];
int dp[200005][N];
int32_t main()
{
speed;
int tt=1;//cin>>tt;
while(tt--){
//freopen("teamwork.in","r",stdin);
//freopen("teamwork.out","w",stdout);
int n,w;cin>>w>>n;
if(n==1){
int x,y,k;cin>>x>>y>>k;
cout<<min(k,w/y)*x;
return 0;
}
vector<array<int,2>> a;
f1(n){
int w,v,k;cin>>v>>w>>k;
k=min(k,(int)2000);
while(k--)a.pb({v,w});
}
for(int i=(int)a.size()-1;i>=0;i--){
for(int j=w;j>=0;j--){
dp[i][j]=max(dp[i+1][j],(j+a[i][1]<=w ? dp[i+1][j+a[i][1]]+a[i][0]:0));
}
}
cout<<dp[0][0];
}
}
Compilation message (stderr)
/tmp/ccJ6cNkW.o: in function `__tcf_0':
knapsack.cpp:(.text+0x9): relocation truncated to fit: R_X86_64_PC32 against symbol `adj' defined in .bss section in /tmp/ccJ6cNkW.o
/tmp/ccJ6cNkW.o: in function `main':
knapsack.cpp:(.text.startup+0xf): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
knapsack.cpp:(.text.startup+0x3e): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
knapsack.cpp:(.text.startup+0x49): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
knapsack.cpp:(.text.startup+0x213): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
knapsack.cpp:(.text.startup+0x277): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
/tmp/ccJ6cNkW.o: in function `_GLOBAL__sub_I_adj':
knapsack.cpp:(.text.startup+0x2c1): relocation truncated to fit: R_X86_64_PC32 against `.bss'
knapsack.cpp:(.text.startup+0x2e6): relocation truncated to fit: R_X86_64_PC32 against symbol `adj' defined in .bss section in /tmp/ccJ6cNkW.o
/usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(vterminate.o): in function `__gnu_cxx::__verbose_terminate_handler()':
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x1e): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x2b): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
/usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(ios_init.o): in function `std::ios_base::Init::Init()':
(.text._ZNSt8ios_base4InitC2Ev+0x1c): failed to convert GOTPCREL relocation against '_ZNSt8ios_base4Init11_S_refcountE'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x60): additional relocation overflows omitted from the output
(.text._ZNSt8ios_base4InitC2Ev+0x1c6): failed to convert GOTPCREL relocation against '_ZSt4cout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x260): failed to convert GOTPCREL relocation against '_ZSt3cin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x2e2): failed to convert GOTPCREL relocation against '_ZSt4cerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x353): failed to convert GOTPCREL relocation against '_ZSt4clog'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x541): failed to convert GOTPCREL relocation against '_ZSt5wcout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x5e5): failed to convert GOTPCREL relocation against '_ZSt4wcin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x670): failed to convert GOTPCREL relocation against '_ZSt5wcerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x6e9): failed to convert GOTPCREL relocation against '_ZSt5wclog'; relink with --no-relax
/usr/bin/ld: final link failed
collect2: error: ld returned 1 exit status