이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ar array
const int INF = 1e17;
const int N = 4e3 + 20;
const int MOD = 1e9 + 7;
const int X = 31;
int n, m;
vector<ar<int, 3> > A;
bool comp(ar<int, 3> a, ar<int, 3> b){
if(a[1] != b[1])return a[1] > b[1];
return a[0] >= b[0];
}
int dp[2][X];
signed main(){ios_base::sync_with_stdio(false);cin.tie(0);
cin>>n;
while(n--){
int x, y, z;
cin>>x>>y>>z;
A.push_back({x, y, -z});
}
cin>>n;
while(n--){
int x, y, z;
cin>>x>>y>>z;
A.push_back({-x, y, z});
}
n = A.size();
sort(A.begin(), A.end(), comp);
int k = 0;
//for(auto [a, b, c]: A)cout<<a<<" "<<" "<<b<<" "<<c<<endl;
for(int i = 0;i < X;i++)dp[k][i] = -INF;
dp[k][0] = 0;
for(int i = 0;i < n;i++,k ^= 1){
memcpy(dp[k ^ 1], dp[k], sizeof dp[k]);
auto [a, garbage, b] = A[i];
for(int j = 0;j < X;j++){
// cout<<dp[k][j]<<" ";
if(j + a < 0 || j + a >= X || dp[k][j] == -INF)continue;
dp[k ^ 1][j + a] = max(dp[k ^ 1][j + a], dp[k][j] + b);
}
//cout<<endl;
}
// for(int i = 0;i < X;i++)cout<<dp[k][i]<<" ";
cout<<*max_element(dp[k], dp[k] + X);
}
//! MI SE SPIEEEEE!
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:46:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
46 | auto [a, garbage, b] = A[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... |