Submission #1103163

#TimeUsernameProblemLanguageResultExecution timeMemory
1103163khoile08Knapsack (NOI18_knapsack)C++14
73 / 100
1065 ms19904 KiB
#include <bits/stdc++.h>
using namespace std;
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FOD(i,a,b) for(int i = a; i >= b; i--)
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define lcm(a,b) (a*b)/__gcd(a,b)
#define ii pair<int,int>
#define iii pair<int,pair<int,int>>
#define iv pair<pair<int,int>,pair<int,int>>

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 105;
const int S = 2005;

const int dx[] = {-1,0,1,0};
const int dy[] = {0,1,0,-1};
const int dxx[] = {-1,-1,0,1,1,1,0,-1};
const int dyy[] = {0,1,1,1,0,-1,-1,-1};

int n, s;
ll dp[S];
vector<pair<ll,ll>> a;

void solve()
{
	for(int i = 0; i < a.size(); i++)
	{
		for(int j = s; j >= 0; j--)
		{
			if(j >= a[i].se)
				dp[j] = max(dp[j], dp[j-a[i].se] + a[i].fi);
		}
	}
	cout << dp[s];
}

void input()
{
	//freopen("TEST.INP", "r", stdin);
	//freopen("TEST.OUT", "w", stdout);
	cin >> s >> n;
	FOR(i,1,n)
	{
		ll v, w, num;
		cin >> v >> w >> num;
		ll pw = 1;
		while(num >= pw)
		{
			num -= pw;
			a.pb({v*pw,w*pw});
			pw <<= 1;
		}
		if(num)
			a.pb({v*num,w*num});
	}
}

signed main()
{
	faster
	input();
	solve();
}

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:33:19: 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]
   33 |  for(int i = 0; i < a.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...