AcWing 4700. 何以包邮?
原题链接
简单
作者:
Coinisi.
,
2023-01-13 09:20:35
,
所有人可见
,
阅读 172
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#define IOS std::ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define int long long
#define x first
#define y second
#define cmp [&](PII a, PII b){return a.y < b.y;}
const int N = 5e5+10, mod = 1e9+7, M = 5e7+5, K = 2e5+10, Z = 1e5+7, X = 3e5+3;
using namespace std;
typedef long long LL;
typedef priority_queue<int> PQI;
typedef priority_queue <int, vector<int>, greater<>> PQGI;
typedef pair<int, int> PII;
int dp[X];
void solve()
{
int n, x; cin >> n >> x;
memset(dp, 0x3f, sizeof dp);
dp[0] = 0;
for(int i = 1; i <= n; i ++)
{
int v; cin >> v;
int w = v;
for(int j = x; j >= 0; j --)
{
dp[j] = min(dp[j], dp[max(0LL, j - v)] + w);
// cout << dp[j] << endl;
}
}
cout << dp[x] << endl;
}
signed main()
{
IOS; int T = 1;
cin.tie(nullptr);
cout.tie(nullptr);
// cin >> T;
while( T -- ) solve();
return 0;
}