Submission #994432

#TimeUsernameProblemLanguageResultExecution timeMemory
994432cpdreamerCloud Computing (CEOI18_clo)C++14
18 / 100
250 ms2068 KiB
#include <bits/stdc++.h> #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 = 1000000007; // 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); } void solve(){ int n; cin>>n; int C[n],P[n]; for(int i=0;i<n;i++){ int b; cin>>C[i]>>b>>P[i]; } int m;cin>>m; int C1[m],P1[m]; for(int i=0;i<m;i++){ int b; cin>>C1[i]>>b>>P1[i]; } ll Buy[(int)1e5+1]; ll Sell[(int)1e5+1]; memset(Buy,-1,sizeof(Buy)); memset(Sell,-1,sizeof(Sell)); Buy[0]=0; Sell[0]=0; for(int i=0;i<n;i++){ for(int j=1e5;j>=C[i];j--){ if(Buy[j-C[i]]!=-1){ if(Buy[j]!=-1){ Buy[j]=min(Buy[j],Buy[j-C[i]]+P[i]); } else Buy[j]=Buy[j-C[i]]+P[i]; } } } for(int i=0;i<m;i++){ for(int j=1e5;j>=C1[i];j--){ if(Sell[j-C1[i]]!=-1){ if(Sell[j]!=-1){ Sell[j]=max(Sell[j],Sell[j-C1[i]]+P1[i]); } else Sell[j]=Sell[j-C1[i]]+P1[i]; } } } int index; for(int i=0;i<=1e5;i++){ if(Buy[i]!=-1) index=i; } ll s=Buy[index]; for(int i=index;i>=0;i--){ if(Buy[i]!=-1){ Buy[i]=min(s,Buy[i]); s=min(s,Buy[i]); } } ll ans=0; for(int i=0;i<=1e5;i++){ if(Buy[i]!=-1 && Sell[i]!=-1){ ans=max(ans,Sell[i]-Buy[i]); } } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //file(); solve(); return 0; }

Compilation message (stderr)

clo.cpp: In function 'void file()':
clo.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen("input.txt.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen("output.txt.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp: In function 'void setio(std::string)':
clo.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp: In function 'void solve()':
clo.cpp:73:9: warning: 'index' may be used uninitialized in this function [-Wmaybe-uninitialized]
   73 |     int index;
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...