3 solutions

  • 0
    @ 2025-8-9 16:09:48

    #include<bits/stdc++.h> using namespace std; const int N=101,M=101; int f[N][M],v[N],w[N]; int main() { int n,V; cin>>n>>V; for(int i=1;i<=V;i++) { cin>>v[i]>>w[i]; } for(int i=1;i<=V;i++) { for(int j=1;j<=n;j++) { f[i][j]=f[i-1][j-1]; if(j>v[i+1]) { f[i][j]=max(f[i][j],f[i-1][j-1]+w[i]); } } } cout<<f[n][V]; return 0; }

    Information

    ID
    986
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    5
    Tags
    (None)
    # Submissions
    60
    Accepted
    18
    Uploaded By