Submission #788056

#TimeUsernameProblemLanguageResultExecution timeMemory
788056AndreyKnapsack (NOI18_knapsack)C++14
100 / 100
52 ms5068 KiB
#include <bits/stdc++.h>
using namespace std;

vector<pair<long long,long long>> haha[2001];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n,a,b,c,s,y,ans = 0;
    cin >> s >> n;
    for(long long i = 0; i < n; i++) {
        cin >> a >> b >> c;
        haha[b].push_back({a,c});
    }
    vector<pair<long long,long long>> bruh(0);
    for(long long i = 1; i <= s; i++) {
        sort(haha[i].begin(),haha[i].end());
        reverse(haha[i].begin(),haha[i].end());
        c = s/i;
        y = 0;
        while(c > 0 && !haha[i].empty()) {
            if(haha[i][y].second == 0) {
                y++;
                if(y >= haha[i].size()) {
                    break;
                }
            }
            bruh.push_back({i,haha[i][y].first});
            haha[i][y] = {haha[i][y].first,haha[i][y].second-1};
            c--;
        }
    }
    vector<long long> dp(s+1);
    for(long long i = 0; i < bruh.size(); i++) {
        a = bruh[i].first;
        b = bruh[i].second;
        for(long long j = s; j >= a; j--) {
            dp[j] = max(dp[j],dp[j-a]+b);
            ans = max(ans,dp[j]);
        }
    }
    cout << ans;
    return 0;
}

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:26:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |                 if(y >= haha[i].size()) {
      |                    ~~^~~~~~~~~~~~~~~~~
knapsack.cpp:36:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(long long i = 0; i < bruh.size(); i++) {
      |                          ~~^~~~~~~~~~~~~
#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...