# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
370056 | 79brue | Travelling Merchant (APIO17_merchant) | C++14 | 120 ms | 4204 KiB |
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;
typedef long long ll;
int n, m, k;
vector<pair<int, ll> > link[102];
ll buy[102][1002], sell[102][1002];
ll dist[102][102];
ll profit[102][102];
ll tDist[102][102];
bool able(ll key){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
tDist[i][j] = profit[i][j] - key * dist[i][j];
}
}
for(int d=1; d<=n; d++){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
tDist[i][j] = max(tDist[i][j], tDist[i][d] + tDist[d][j]);
}
}
}
for(int i=1; i<=n; i++){
if(tDist[i][i] >= 0) return true;
}
return false;
}
int main(){
scanf("%d %d %d", &n, &m, &k);
for(int i=1; i<=n; i++){
for(int j=1; j<=k; j++){
scanf("%lld %lld", &buy[i][j], &sell[i][j]);
}
}
for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) dist[i][j] = 1e9;
for(int i=1; i<=m; i++){
int x, y; ll z;
scanf("%d %d %lld", &x, &y, &z);
dist[x][y] = z;
}
for(int d=1; d<=n; d++){
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
dist[i][j] = min(dist[i][j], dist[i][d] + dist[d][j]);
}
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
for(int x=1; x<=k; x++){
if(min({sell[j][x], buy[i][x]}) == -1) continue;
profit[i][j] = max(profit[i][j], sell[j][x] - buy[i][x]);
}
}
}
ll MIN = 0, MAX = 1e9, ANS = 0;
while(MIN <= MAX){
ll MID = (MIN + MAX) / 2;
if(able(MID)){
ANS = MID;
MIN = MID+1;
}
else MAX = MID-1;
}
printf("%lld", ANS);
}
Compilation message (stderr)
# | 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... |