#include <stdio.h>
int route[2001][2001]={};
int box[2001]={};
int n,c,m,max = 0;
void a(int i,int j){
if(c != 0){
box[j] += c;
route[i][j] -= c;
c = 0;
}
for(int l = n;l > j;l--){
if(box[l] == 0)
continue ;
if(box[l] - route[i][j] >= 0){
box[l] -= route[i][j];
box[j] += route[i][j];
return ;
}
route[i][j] -= box[l];
box[j] += box[l];
box[l] = 0;
}
}
int main(){
scanf("%d %d",&n,&c);
scanf("%d",&m);
for(int i = 0;m > i;i++){
int j,l,k;
scanf("%d %d %d",&j,&l,&k);
route[j][l]=k;
}
int i = 1;
while(1){
for(int j = i + 1;j <= n;j++){
if(c - route[i][j] >= 0){
c -= route[i][j];
box[j] += route[i][j];
}
else
a(i,j);
}
i++;
max += box[i];
c += box[i];
if(i == n)
break ;
}
printf("%d",max);
}
top of page

기능을 테스트하려면 라이브 사이트로 이동하세요.
수정: 2024년 2월 14일
택배
택배
댓글 0개
좋아요
댓글(0)
bottom of page