이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define piii pair<pair<int,int>,pair<int,int>>
#define pip pair<int,pair<int,int>>
int dp[100005];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n; cin >> n;
vector<piii>v;
for(int i = 1; i <= n; i++){
int c,f,h; cin >> c >> f >> h;
v.pb({{f,1},{c,h}});
}
int m; cin >> m;
for(int i = 1; i <= m; i++){
int c,f,h; cin >> c >> f >> h;
v.pb({{f,-1},{c,h}});
}
for(int i = 1; i <= 100000; i++){
dp[i] = -1e18;
}
sort(v.begin(), v.end(), greater<piii>());
for(int i = 0; i < v.size(); i++){
//cout << "here1 >> " << i << endl;
if(v[i].fi.se == 1){
for(int j = 100000; j >= 1; j--){
if(j - v[i].se.fi < 0 || dp[j - v[i].se.fi] == -1e18)continue;
else{
dp[j] = max(dp[j], dp[j - v[i].se.fi] - v[i].se.se);
}
}
}
else{
for(int j = 0; j <= 100000; j++){
if(j + v[i].se.fi > 100000 || dp[j + v[i].se.fi] == -1e18)continue;
else{
dp[j] = max(dp[j], dp[j + v[i].se.fi] + v[i].se.se);
}
}
}
// for(int i = 1; i <= 10; i++){
// cout << "here >> " << dp[i] << endl;
// }
}
int ans = 0;
for(int i = 0; i <= 100000; i++){
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:31:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 0; i < v.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... |