#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define N 1000003
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e17, MOD = INF + 7, MOD2 = 1e6 + 3;
ll un_dist[100][100], deal[100][100];
ll sell[100][100], buy[100][100], n, m, k;
ll d[100][100];
bool check (int x) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (un_dist[i][j] == INF) d[i][j] = -INF;
else d[i][j] = deal[i][j] - x * un_dist[i][j];
}
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (d[i][j] < d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];
for (int i = 0; i < n; i++)
if (d[i][i] >= 0) return true;
return false;
}
int main () {
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < k; j++) {
int b, s;
cin >> buy[i][j] >> sell[i][j];
}
for (int i = 0; i < n; i++)
fill (un_dist[i], un_dist[i] + n, (int) INF);
for (int i = 0; i < m; i++) {
int u, v, l;
cin >> u >> v >> l;
u--, v--;
un_dist[u][v] = l;
}
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
un_dist[i][j] = min (un_dist[i][j], un_dist[i][k] + un_dist[k][j]);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int it = 0; it < k; it++)
if (sell[j][it] > 0 && buy[i][it] > 0)
deal[i][j] = max (deal[i][j], sell[j][it] - buy[i][it]);
int l = 0, r = 1e9;
while (l < r) {
int mid = (l + r + 1) / 2;
if (check (mid)) l = mid;
else r = mid - 1;
}
cout << l << endl;
}
Compilation message
merchant.cpp: In function 'int main()':
merchant.cpp:43:8: warning: unused variable 'b' [-Wunused-variable]
int b, s;
^
merchant.cpp:43:11: warning: unused variable 's' [-Wunused-variable]
int b, s;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
147 ms |
1016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
512 KB |
Output is correct |
2 |
Correct |
10 ms |
512 KB |
Output is correct |
3 |
Correct |
11 ms |
640 KB |
Output is correct |
4 |
Correct |
10 ms |
512 KB |
Output is correct |
5 |
Correct |
19 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
11 ms |
512 KB |
Output is correct |
8 |
Correct |
11 ms |
640 KB |
Output is correct |
9 |
Correct |
10 ms |
512 KB |
Output is correct |
10 |
Correct |
11 ms |
512 KB |
Output is correct |
11 |
Correct |
14 ms |
640 KB |
Output is correct |
12 |
Correct |
14 ms |
640 KB |
Output is correct |
13 |
Correct |
13 ms |
516 KB |
Output is correct |
14 |
Correct |
12 ms |
512 KB |
Output is correct |
15 |
Correct |
16 ms |
640 KB |
Output is correct |
16 |
Correct |
10 ms |
512 KB |
Output is correct |
17 |
Correct |
21 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
22 ms |
640 KB |
Output is correct |
20 |
Correct |
22 ms |
640 KB |
Output is correct |
21 |
Correct |
15 ms |
640 KB |
Output is correct |
22 |
Correct |
11 ms |
640 KB |
Output is correct |
23 |
Correct |
11 ms |
512 KB |
Output is correct |
24 |
Correct |
9 ms |
512 KB |
Output is correct |
25 |
Correct |
13 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
12 ms |
512 KB |
Output is correct |
28 |
Correct |
14 ms |
512 KB |
Output is correct |
29 |
Correct |
10 ms |
512 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
12 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
888 KB |
Output is correct |
2 |
Incorrect |
256 ms |
2552 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
512 KB |
Output is correct |
2 |
Correct |
10 ms |
512 KB |
Output is correct |
3 |
Correct |
11 ms |
640 KB |
Output is correct |
4 |
Correct |
10 ms |
512 KB |
Output is correct |
5 |
Correct |
19 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
11 ms |
512 KB |
Output is correct |
8 |
Correct |
11 ms |
640 KB |
Output is correct |
9 |
Correct |
10 ms |
512 KB |
Output is correct |
10 |
Correct |
11 ms |
512 KB |
Output is correct |
11 |
Correct |
14 ms |
640 KB |
Output is correct |
12 |
Correct |
14 ms |
640 KB |
Output is correct |
13 |
Correct |
13 ms |
516 KB |
Output is correct |
14 |
Correct |
12 ms |
512 KB |
Output is correct |
15 |
Correct |
16 ms |
640 KB |
Output is correct |
16 |
Correct |
10 ms |
512 KB |
Output is correct |
17 |
Correct |
119 ms |
888 KB |
Output is correct |
18 |
Incorrect |
256 ms |
2552 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |