이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/// punch then pray
#include<bits/stdc++.h>
//#define int long long
#define pii pair<int,int>
#define fi first
#define se second
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
const int N = (int)1e5 ;
const int maxN = (int)5e5 + 1;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infty = 1e18 + 7;
const int base = (int)4e5;
const int block_size = 710;
void InputFile()
{
//freopen("feast.in","r",stdin);
//freopen("feast.out","w",stdout);
//freopen("test.inp","r",stdin);
//freopen("test.out","w",stdout);
}
void FastInput()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
struct Tdata
{
int val,wei,cop;
};
int S,n;
Tdata a[maxN];
int dp[2][2001];
vector<int> save[2001];
bool FA(Tdata x,Tdata y)
{
return x.val > y.val;
}
void Read()
{
cin >> S >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i].val >> a[i].wei >> a[i].cop;
}
sort(a + 1,a + n + 1,FA);
for(int i = 1;i <= n;i++)
{
while(save[a[i].wei].size() < (S / a[i].wei) && a[i].cop > 0)
{
save[a[i].wei].push_back(a[i].val);
a[i].cop--;
}
}
for(int i = 1;i <= S;i++)
{
int cur = i & 1;
int pre = cur ^ 1;
for(int j = 0;j <= S;j++)
{
dp[cur][j] = dp[pre][j];
int used = 0;
int sum = 0;
for(int k : save[i])
{
sum += k;
used++;
if(used * i > j) break;
dp[cur][j] = max(dp[cur][j],dp[pre][j-used*i] + sum);
}
}
}
cout << dp[S&1][S];
}
void Solve()
{
}
int32_t main()
{
FastInput();
//InputFile();
//int sub_type;
//cin >> sub_type;
//Sieve()
int test;
//cin >> test;
test = 1;
while(test--)
{
Read();
Solve();
//Debug();
}
}
////
/////
//////
컴파일 시 표준 에러 (stderr) 메시지
knapsack.cpp: In function 'void Read()':
knapsack.cpp:63:37: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
63 | while(save[a[i].wei].size() < (S / a[i].wei) && a[i].cop > 0)
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |