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;
vector<vector<pair<int,int>>> items;
vector<vector<pair<int,int>>> lst;
vector<int> visited;
vector<pair<vector<int>,int>> ans;
void dfs(int nodo, vector<int> cur, int d){
visited[nodo] += 1;
for(auto vecino:lst[nodo]){
if(vecino.first==0){
d += vecino.second;
ans.push_back({cur,d});
//for(auto a:cur) cout << a << " ";
//cout << endl;
//cout << "d: " << d << endl;
return;
}
if(visited[vecino.first]>1) continue;
cur.push_back(vecino.first);
dfs(vecino.first, cur, d+vecino.second);
cur.pop_back();
}
}
int main(){
int n,m,k,v,w,t;
cin >> n >> m >> k;
// items --> vector[market][item][0-->buy / 1-->sell]
items = vector<vector<pair<int,int>>>(n,vector<pair<int,int>>(k));
lst = vector<vector<pair<int,int>>>(m,vector<pair<int,int>>());
for(int i=0;i<n;i++){
for(int j=0;j<k;j++){
cin >> items[i][j].first >> items[i][j].second;
}
}
for(int i=0;i<m;i++){
cin >> v >> w >> t;
lst[v-1].push_back({w-1,t});
}
// busco cíclos
visited = vector<int>(n,0);
dfs(0, {0}, 0);
int res = 0;
for(auto p:ans){
//cout << p.second << endl;
vector<int> v = p.first;
int profit = 0;
for(int item=0;item<k;item++){
// para cada item, buscamos el max provecho
if(items[0][item].first==-1) continue;
for(int market:v){
if(items[market][item].second==-1) continue;
profit = max(profit, items[market][item].second-items[0][item].first);
}
}
res = max(res, profit/p.second);
}
cout << res << endl;
}
# | 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... |