163322025-04-28 17:39:34ubormaciJobstown-i milliomoscpp17Runtime error 25/100252ms262144 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <fstream>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <type_traits>
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
// #pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*

notes:

int64_t
stoi(string s) -> string to int
to_string() -> int (or else) to string

vector declaration:
vector<ll> v(n, 0)
vector<vector<ll>> v(n, vector<ll>(n, 0));

{if statement} ? {truth value} : {false value}

set lower bound/upper bound:
 	// . . . m1 . . . d . . . . m2
    auto m1_it = b.lower_bound(d);
    advance(m1_it, -1);
    m1 = *m1_it;
	m2 = *b.upper_bound(d);

#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

constexpr auto lcm(auto x, auto... xs)
{
	return ((x = std::lcm(x, xs)), ...);
}

std::gcd(int a, int b)

cout << setprecision(n);

set with custom ordering
set<ll, decltype(&cmp)> qu(cmp);

*/

typedef long long ll;

void solve() {
	
	// knapsack
	ll n, m;
	cin >> n >> m;

	vector<ll> weight(n+1, 0);
	vector<ll> value(n+1, 0);

	for(ll i = 1; i <= n; i++) {
		cin >> weight[i];
	}
	for(ll i = 1; i <= n; i++) {
		cin >> value[i];
	}

	// na jo
	// vajon az, hogy egy elemet tobbszor kivalaszthatunk
	// az azt jelenti, hogy mukodne a greedy, hogy a legjobb ar/ertek aranyu elemet elvesszuk amig mar nem tuddjuk?

	// oke, gyorsan utanaolvastam cp-algorithms-en
	// amugy tudom hogy ez nem lesz jo, mert 500 * 10^9-en kikesziti a szegeny gepet
	// de lassuk

	vector<ll> dp(m+1, 0);

	for (int i = 1; i <= n; i++) {
  		for (int j = weight[i]; j <= m; j++) {
    		dp[j] = max(dp[j], dp[j - weight[i]] + value[i]);
		}	
	}

	cout << dp[m];
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);

	solve();

	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted1ms316 KiB
subtask225/25
3Accepted1ms316 KiB
4Accepted1ms316 KiB
5Accepted25ms820 KiB
6Accepted25ms820 KiB
7Accepted25ms640 KiB
8Accepted25ms820 KiB
9Accepted25ms684 KiB
10Accepted25ms820 KiB
11Accepted35ms820 KiB
12Accepted35ms824 KiB
13Accepted35ms820 KiB
14Accepted1ms820 KiB
subtask30/16
15Runtime error230ms262144 KiB
16Runtime error199ms262144 KiB
17Runtime error245ms262144 KiB
18Runtime error202ms262144 KiB
19Runtime error247ms262144 KiB
20Runtime error196ms262144 KiB
21Runtime error243ms262144 KiB
subtask40/59
22Accepted1ms316 KiB
23Accepted1ms512 KiB
24Runtime error219ms262144 KiB
25Runtime error204ms262144 KiB
26Runtime error202ms262144 KiB
27Runtime error243ms262144 KiB
28Runtime error252ms262144 KiB
29Runtime error202ms262144 KiB
30Runtime error243ms262144 KiB
31Runtime error202ms262144 KiB
32Runtime error204ms262144 KiB
33Runtime error245ms262144 KiB