#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define pi pair<int,int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
template<class T> using upq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());}
template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());}
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define sumof(x) accumulate(all(x), 0ll)
#define dbg(x) "[" << #x " = " << (x) << "]"
#define el "\n"
using ll = long long;
using ld = long double;
template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);}
template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);}
const ll INF = 1e15;
void Main()
{
int n,m,k; cin >> n >> m >> k;
vector<vi> b(n + 1, vi(k + 1)), s(n + 1, vi(k + 1));
FOR(i, 1, n){
FOR(j, 1, k){
cin >> b[i][j] >> s[i][j];
}
}
vector<vector<ll>> profit(n + 1, vector<ll>(n + 1));
FOR(i, 1, n){
FOR(j, 1, n){
FOR(x, 1, k){
if(s[j][x] == -1 || b[i][x] == -1) continue;
ckmx(profit[i][j], 1ll * s[j][x] - b[i][x]);
}
}
}
vector<vector<ll>> d(n + 1, vector<ll>(n + 1, INF));
FOR(i, 1, m){
int u,v,w; cin >> u >> v >> w;
ckmn(d[u][v], 1ll * w);
}
FOR(k, 1, n){
FOR(u, 1, n){
FOR(v, 1, n){
ckmn(d[u][v], d[u][k] + d[k][v]);
}
}
}
vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, INF));
auto good = [&](ll eff) -> bool{
// sum profit / time = eff => sum profit >= time * eff
FOR(u, 1, n){
FOR(v, 1, n){
if(u == v) dp[u][v] = INF;
else{
dp[u][v] = (d[u][v] == INF ? INF : d[u][v] * eff);
}
dp[u][v] = -dp[u][v] + profit[u][v];
// if(dp[u][v] > 0){
// cout << u <<" " << v << " " << d[u][v] <<" " << profit[u][v] << el;
// }
}
}
FOR(k, 1, n){
FOR(u, 1, n){
FOR(v, 1, n){
ckmx(dp[u][v], dp[u][k] + dp[k][v]);
}
}
}
FOR(i, 1, n) if(dp[i][i] >= 0) return true;
return false;
};
//cout << good(2) << el; return;
int l = 0, r = 1e9;
while(l + 1 < r){
int m = l + r >> 1;
(good(m) ? l = m : r = m);
}
cout << l << el;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
int t = 1; while(t--) Main();
return 0;
}
Compilation message (stderr)
merchant.cpp: In function 'int32_t main()':
merchant.cpp:119:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
119 | freopen(name".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:120:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
120 | freopen(name".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |