이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// bruh this time complexity is so bad
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
const ll INFL = 1e18;
struct OP {
ll op,kt,val,so;
OP(ll op_, ll kt_, ll val_, ll so_): op(op_), kt(kt_), val(val_), so(so_) {
}
bool operator<(const OP& ot) const {
if(so != ot.so) {return so > ot.so;}
return op > ot.op;
};
};
int main() {
ios::sync_with_stdio(0);cin.tie(0);
vector<OP> ops;
ll n;
cin >> n;
for(int i=0;i<n;i++) {
ll kt,so,val;
cin >> kt >> so >> val;
ops.emplace_back(1,kt,val,so);
}
ll m;
cin >> m;
for(int i=0;i<m;i++) {
ll kt,so,val;
cin >> kt >> so >> val;
ops.emplace_back(-1,kt,val,so);
}
sort(ops.begin(),ops.end());
vector<ll> dp;
dp.push_back(0);
for(const auto& op: ops) {
if(op.op == 1) {
dp.resize(dp.size()+op.kt,-INFL);
for(int i=dp.size()-1;i>=op.kt;i--) {
dp[i] = max(dp[i],dp[i-op.kt]-op.val);
}
} else {
for(int i=0;i+op.kt<dp.size();i++) {
dp[i] = max(dp[i],dp[i+op.kt]+op.val);
}
}
}
ll ans = 0;
for(int i=0;i<dp.size();i++) {
ans = max(ans,dp[i]);
}
cout << ans << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:44:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0;i+op.kt<dp.size();i++) {
| ~~~~~~~^~~~~~~~~~
clo.cpp:50:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=0;i<dp.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... |