#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define ff first
#define ss second
int N, M, K;
int B[101][1000], S[101][1000], E[101][101];
ll 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] = m * E[i][j] - W[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] = min(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 x = 1; x <= N; ++x) for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j)
if (i != j && E[i][x] && E[x][j] && (!E[i][j] || E[i][j] > E[i][x] + E[x][j])) 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(0, S[j][k] - B[i][k]);
ll l = 0, r = 1e12;
while (l < r) {
ll m = l + r + 1 >> 1;
if (f(m)) l = m;
else r = m - 1;
}
cout << r;
return 0;
}
Compilation message
merchant.cpp: In function 'int main()':
merchant.cpp:38:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll m = l + r + 1 >> 1;
~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
80 ms |
1272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
896 KB |
Output is correct |
2 |
Correct |
10 ms |
1024 KB |
Output is correct |
3 |
Correct |
10 ms |
896 KB |
Output is correct |
4 |
Correct |
9 ms |
896 KB |
Output is correct |
5 |
Incorrect |
10 ms |
896 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
54 ms |
1280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
896 KB |
Output is correct |
2 |
Correct |
10 ms |
1024 KB |
Output is correct |
3 |
Correct |
10 ms |
896 KB |
Output is correct |
4 |
Correct |
9 ms |
896 KB |
Output is correct |
5 |
Incorrect |
10 ms |
896 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |