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;
using ll = long long;
int N, M, K;
int B[101][1000], S[101][1000], E[101][101], W[101][101];
bool f(ll m) {
ll X[101][101] = {0};
for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) X[i][j] = W[i][j] - m * E[i][j];
for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) for (int k = 1; k <= N; ++k) {
if (j != k) X[j][k] = max(X[j][k], X[j][i] + X[i][k]);
}
for (int i = 1; i < N; ++i) for (int j = i + 1; j <= N; ++j) if (X[i][j] + X[j][i] >= 0) return 1;
return 0;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> M >> K;
for (int i = 1; i <= N; ++i) for (int j = 0; j < K; ++j) cin >> B[i][j] >> S[i][j];
for (int i = 0; i < M; ++i) {
int a, b, c; cin >> a >> b >> c;
E[a][b] = c;
}
for (int i = 1; i <= N; ++i) fill(E[i] + 1, E[i] + N + 1, 1e9);
for (int x = 1; x <= N; ++x) for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j)
E[i][j] = min(E[i][j], E[i][x] + E[x][j]);
for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) for (int k = 0; k < K; ++k)
if(S[j][k] > 0 && B[i][k] > 0) W[i][j] = max(W[i][j], S[j][k] - B[i][k]);
int l = 0, r = 1e9;
while (l < r) {
int m = l + r + 1 >> 1;
if (f(m)) l = m;
else r = m - 1;
}
cout << r;
return 0;
}
Compilation message (stderr)
merchant.cpp: In function 'int main()':
merchant.cpp:35:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r + 1 >> 1;
~~~~~~^~~
# | 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... |