제출 #447793

#제출 시각아이디문제언어결과실행 시간메모리
447793Killer2501Knapsack (NOI18_knapsack)C++14
100 / 100
102 ms14004 KiB
#include<bits/stdc++.h>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define pii pair<ll, pll>
using namespace std;
using ll = int;
const int  N = 2e5+55;
const ll mod = 1e9+7;
const ll mod1 = 1e9+1;
const ll base = 311;
const ll base1 = 331;
ll m, n, t, k, a[N], tong, b[N], dp[N], c[N], lab[N], cnt, ans;
string s[N];
vector<pll> adj[N];
vector<pll> e;
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> m >> n;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i] >> b[i] >> c[i];
        adj[b[i]].pb({a[i], c[i]});
    }
    for(int i = 1; i <= m; i ++)
    {
        sort(adj[i].rbegin(), adj[i].rend());
        tong = i;
        for(pll x : adj[i])
        {
            if(tong > m)break;
            for(int j = 1; j <= x.se && tong <= m; j ++, tong += i)
            {
                for(int p = m; p >= i; p --)
                {
                    dp[p] = max(dp[p], dp[p-i] + x.fi);
                    ans = max(ans, dp[p]);
                }
            }
        }
    }
    cout << ans;
}
/*
1
5 9
1 2 3 2
1 3 2 -2
2 2 3
1 3 2 -3
2 2 3
1 1 4 7
1 4 5 8
2 5 2
2 5 1
1 5 6
1 1 2 2
1 2 4 3
2 1 4
1 1 5 6
1 2 3 -2
2 3 5
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...