이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct task {
int t, c, f, v;
};
const int MAX_N = 2000;
const int MAX_M = 2000;
const int MAX_C = 50;
const int MAX_CORES = MAX_M * MAX_C;
const long long INF = 1e15;
vector<task> events;
long long dp[MAX_CORES + 1];
int main() {
int n, m;
cin >> n;
for ( int i = 0; i < n; i++ ) {
int c, f, v;
cin >> c >> f >> v;
events.push_back( { 0, c, f, v } );
}
cin >> m;
for ( int i = 0; i < m; i++ ) {
int c, f, v;
cin >> c >> f >> v;
events.push_back( { 1, c, f, v } );
}
sort( events.begin(), events.end(), []( task a, task b ) {
if ( a.f == b.f )
return a.t < b.t;
return a.f > b.f;
} );
dp[0] = 0;
for ( int p = 1; p <= MAX_CORES; p++ )
dp[p] = -INF;
for ( auto e: events ) {
if ( e.t == 0 ) {
for ( int p = MAX_CORES; p - e.c >= 0; p-- )
dp[p] = max( dp[p], dp[p - e.c] - e.v );
} else {
for ( int p = 0; p + e.c <= MAX_CORES; p++ )
dp[p] = max( dp[p], dp[p + e.c] + e.v );
}
}
long long ans = 0;
for ( int p = 0; p <= MAX_CORES; p++ )
ans = max( ans, dp[p] );
cout << ans;
return 0;
}
# | 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... |