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;
#define ll long long
#define pll pair<ll, ll>
#define maxn 101
#define maxk 1010
int N, M, K;
const ll inf = 1e18;
ll dist[maxn][maxn];
ll buy[maxn][maxk];
ll sell[maxn][maxk];
ll profit[maxn][maxn];
ll d2[maxn][maxn];
bool check(ll val) {
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
d2[i][j] = profit[i][j] - val*min(inf/val, dist[i][j]);
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
for (int k = 1; k <= N; k++) {
d2[i][j] = max(d2[i][j], d2[i][k] + d2[k][j]);
}
}
}
for (int i = 1; i <= N; i++) {
if (d2[i][i] >= 0) return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> M >> K;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
dist[i][j] = inf;
}
dist[i][i] = inf;
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= K; j++) {
cin >> buy[i][j] >> sell[i][j];
}
}
int vp, wp; ll tp;
for (int i = 0; i < M; i++) {
cin >> vp >> wp >> tp;
dist[vp][wp] = min(dist[vp][wp], tp);
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
for (int k = 1; k <= N; k++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (i == j) continue;
for (int k = 1; k <= K; k++) {
if (buy[i][k] == -1 || sell[j][k] == -1) continue;
profit[i][j] = max(profit[i][j], sell[j][k] - buy[i][k]);
}
}
}
ll lo = 0LL;
ll hi = 1e12;
while (lo < hi) {
ll mid = (lo+hi+1)/2LL;
if (check(mid)) {
lo = mid;
}
else hi = mid-1;
}
cout << lo << 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... |