# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
996531 | cpdreamer | Cloud Computing (CEOI18_clo) | C++17 | 161 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const int max_n=INT_MAX;
typedef long long ll;
#define LLM LONG_LONG_MAX
#define pb push_back
#define F first
#define L length()
#define all(v) v.begin(),v.end()
#define V vector
#define S second
const long long MOD = 99824433; // 1e9 + 7
void file(){
freopen("input.txt.txt","r",stdin);
freopen("output.txt.txt","w",stdout);
}
void setio(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
struct computer{
int c;
int p;
int v;
int id;
};
bool sorted(computer a,computer b){
if(a.p==b.p)
return a.id<b.id;
return a.p>b.p;
}
void solve() {
int n;
cin >> n;
V<computer> A;
A.pb({0, 0, 0,0});
ll sum=0;
for (int i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
sum+=a;
A.pb({a, b, -c,-1});
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
sum+=a;
A.pb({-a, b, c,i});
}
sort(A.begin()+1,A.end(), sorted);
bool made[n+m+1][sum+100];
ll dp[n + m + 1][sum+100];
memset(dp, -1, sizeof(dp));
memset(made,false,sizeof(made));
dp[0][0]=0;
made[0][0]=true;
for (int i = 1; i <= n + m; i++) {
for (int j =0; j <= sum; j++) {
if(made[i-1][j]) {
dp[i][j] = dp[i - 1][j];
made[i][j]=true;
}
}
for (int j = max(0, A[i].c); j <=min(sum,sum+A[i].c) ; j++) {
if (made[i - 1][j - A[i].c]) {
if(made[i][j])
dp[i][j] = max(dp[i][j], dp[i - 1][j - A[i].c] + A[i].v);
else
dp[i][j]=dp[i - 1][j - A[i].c] + A[i].v;
made[i][j]=true;
}
}
int k;
k++;
}
ll ans=LONG_LONG_MIN;
for(int i=1;i<=n+m;i++){
for(int j=0;j<=sum;j++){
ans=max(ans,dp[i][j]);
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//file();
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |