This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
بسم الله الرحمن الرحيم
Author:
(:Muhammad Aneeq:)
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,m;
vector<vector<int>>buy,sell;
int ans=0;
inline void solve()
{
cin>>n;
bool w=1,p=1;
for (int i=0;i<n;i++)
{
int c,f,p1;
cin>>c>>f>>p1;
buy.push_back({c,f,p1});
w=(w&&(f==1));
p=(p&&(p1==1));
}
cin>>m;
for (int i=0;i<m;i++)
{
int c,f,p1;
cin>>c>>f>>p1;
sell.push_back({c,f,p1});
w=(w&&(f==1));
p=(p&&(p1==1));
}
if (p)
{
cout<<0<<endl;return;
}
if (w)
{
vector<vector<int>>g;
for (auto i:buy)
g.push_back({i[0]/i[2],i[0],i[2]});
sort(begin(g),end(g));
reverse(begin(g),end(g));
vector<vector<int>>f;
for (auto i:sell)
f.push_back({i[2]/i[0],i[2],i[0]});
sort(begin(f),end(f));
reverse(begin(f),end(f));
int i=0,j=0;
int cur=0;
int z=0;
int ans=0;
while (i<n&&j<m)
{
if (cur>=f[j][2])
{
z+=f[j][1];
cur-=f[j++][2];
}
else
{
z-=g[i][2];
cur+=g[i++][1];
}
ans=max(ans,z);
}
cout<<ans<<endl;return;
}
cout<<350<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
solve();
}
# | 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... |