이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define s second
#define pb push_back
#define f first
using namespace std;
const int N = 100005;
vector<pair<pair<int,int>,int> > vec;
int tot;
ll dpold[N],dpnew[N];
bool cmp(pair<pair<int,int>,int> a, pair<pair<int,int>,int> b){
if (a.f.s < b.f.s) return 0;
if (a.f.s > b.f.s) return 1;
return (a.f.f > b.f.f);
}
signed main() {
int n;
cin>>n;
for (int i = 0; i < n; i++){
int c,f,v;
cin>>c>>f>>v;
tot += c;
vec.pb({{c,f},-v});
}
int m;
cin>>m;
for (int i = 0; i < m; i++){
int c,f,v;
cin>>c>>f>>v;
vec.pb({{-c,f},v});
}
sort(vec.begin(),vec.end(),cmp);
for (int i = 1;i <= tot; i++)
dpold[i] = dpnew[i] = -1e18;
for (int i = 0; i < vec.size(); i++){
int pr = vec[i].s,cr = vec[i].f.f;
for (int j = 0; j <= tot; j++){
int nw = j + cr;
if (nw < 0 || nw > tot || dpold[j] == -1e18) continue;
dpnew[nw] = max(dpnew[nw], dpold[j] + pr);
}
for (int j = 0; j <= tot; j++)
dpold[j] = dpnew[j];
}
ll ans=0;
for (int j = 0; j <= tot; j++)
ans=max(ans,dpold[j]);
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < vec.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... |