# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165388 | Lawliet | Cloud Computing (CEOI18_clo) | C++14 | 13 ms | 1912 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long int lli;
const int MAXN = 300;
int n, m;
lli dp[MAXN][MAXN];
vector< pii > buy;
vector< pii > sell;
lli solve(int i, int j)
{
if( i < 0 || j < 0 ) return 0;
lli& ans = dp[i][j];
if( ans != -1 ) return ans;
ans = max( solve( i - 1 , j ) , solve( i , j - 1 ) );
if( buy[i].first >= sell[j].first )
{
lli cost = sell[j].second - buy[i].second;
ans = max( ans , solve( i - 1 , j - 1 ) + cost );
}
ans = max( ans , 0LL );
return ans;
}
int main()
{
scanf("%d %d",&n,&m);
memset( dp , -1 , sizeof(dp) );
for(int i = 1 ; i <= n ; i++)
{
int c, f, v;
scanf("%d %d %d",&c,&f,&v);
buy.push_back( { f , v } );
}
for(int i = 1 ; i <= m ; i++)
{
int c, f, v;
scanf("%d %d %d",&c,&f,&v);
sell.push_back( { f , v } );
}
sort(buy.begin() , buy.end());
sort(sell.begin() , sell.end());
printf("%lld\n",solve( n - 1 , m - 1 ));
}
Compilation message (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... |