Submission #866371

#TimeUsernameProblemLanguageResultExecution timeMemory
866371phuxtrohhgKnapsack (NOI18_knapsack)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define mp(x) make_pair(x)
#define file "test"
using namespace std;
const double PI = 2 * acos(0);
const long long INF = 1e18;
const long long N = 2e6 + 5;
ll s, n;
ll dp[N];
vector<pii> w[2005];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
    #endif
    cin >> s >> n;
    for (int i = 1; i <=n; i++)
        {
            ll v, wai, k;
            cin >> v >> wai >> k;
            w[wai].push_back({v, k});
        } 
    

    for (int i = 1; i <= s; i++)
        {
            if (!w[i].size()) continue;
            sort(all(w[i]));

            ll curw = i;
            for (int r = 0; r < w[i].size(); r++)
            {
                if (curw > s) break;
                for (int sl = 1; sl <= w[i][r].nd; sl++, curw += i)       
                    for (int j = s; j >= i * sl; j--)
                        dp[j] = max(dp[j], dp[j - i * sl] + w[i][r].st * sl);

            }
            // cout << i <<'\n';
            // for (int i = 1; i <=s; i++)
            //     cout << dp[i] <<' ';
            // cout << '\n';
        }

    // for (int i = 1; i <=n; i++)
    //     {
    //         for (int j = 1; j <= s; j++) 
    //             cout << dp[i][j] <<' ';
    //         cout << '\n';
    //     }
    cout << dp[s];    
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:38:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             for (int r = 0; r < w[i].size(); r++)
      |                             ~~^~~~~~~~~~~~~
knapsack.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:21:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...