이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 int long long
#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 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};
struct dat
{
int c, f, v;
};
bool cmp(dat a, dat b)
{
return a.f != b.f ? a.f > b.f : a.v < b.v;
}
int n, sum, m;
vector<dat> a;
int dp[N][2];
void solve()
{
sort(a.begin(), a.end(), cmp);
FOR(i,1,sum)
dp[i][0] = -INF;
for(int i = 0; i < a.size(); i++)
{
for(int j = 0; j <= sum; j++)
dp[j][1] = dp[j][0];
for(int j = 0; j <= sum; j++)
{
int pre = j - a[i].c;
if(pre >= 0 && pre <= sum && dp[pre][0] != -INF)
dp[j][1] = max(dp[j][1], dp[pre][0] + a[i].v);
}
for(int j = 0; j <= sum; j++)
dp[j][0] = dp[j][1];
}
int ans = -INF;
FOR(i,0,sum)
ans = max(ans, dp[i][0]);
cout << ans;
}
void input()
{
//freopen("TEST.INP", "r", stdin);
//freopen("TEST.OUT", "w", stdout);
cin >> n;
FOR(i,1,n)
{
int c, f, v;
cin >> c >> f >> v;
a.pb({c,f,-v});
sum += c;
}
cin >> m;
FOR(i,1,m)
{
int c, f, v;
cin >> c >> f >> v;
a.pb({-c,f,v});
}
}
signed main()
{
faster
input();
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'void solve()':
clo.cpp:46:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<dat>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0; i < a.size(); i++)
| ~~^~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |