#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int n,m,h;
cin>>n>>m>>h;
vector<vector<pair<int,int>>>adj(n);
for(int x=0;x<n-1;x++){
for(int i=0;i<h;i++)
{
int j,w;
cin>>j>>w;
if(j<=x)continue;
adj[x].push_back({j,w});//ignore those that fail the condition
}
}
vector<vector<int>>base(n,vector<int>(m,0));
base[0][0]=1;//to be in the first city spending no nights
vector<int>dep(m);
for(int i=0;i<n-1;i++)
{int x=0;
for(int t=0;t<m;t++){
x=min(x+base[i][t],500000001LL);
dep[t]=x;
}
for(auto [j,k]:adj[i])
{
if(k>=m)continue;//if min days are way too much
int maxt=m-k-1;
for(int t=0;t<=maxt;t++)
{
base[j][t+k]=min(base[j][t+k]+dep[t],500000001LL);
}
}
}
for(int t=0;t<m;t++)
cout<<min(base[n-1][t],500000001LL)<<" ";
cout<<endl;
return 0;
}
| # | 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... |