Language: C++

#include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    int k[150],xp[150][10],d[150][10];
    for(int i=0;i<n;i++){
      cin>>k[i];
      for(int j=0;j<k[i];j++){
    cin>>xp[i][j]>>d[i][j];
      }
    }
    int c[150][150][10]={{}};
    fill(c[0][0],c[150][0],1<<29);
    fill(c[0][m],c[0][m+1],0);
    if(m>0){
      fill(c[1][m-1],c[1][m],0);
    }
    int ans=1<<30;
    for(int y=0;y<n;y++){
      for(int j=0;j<=m;j++){
    for(int x=0;x<k[y];x++){
      for(int dj=0;dj<=!!j#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#define REP(i,a,n) for(int i = a;i < n;i++)
#define rep(i,n) REP(i,0,n)
#define f first
#define s second
#define mpi(l,m,n,o) make_pair(make_pair(l,m),make_pair(n,o))
#define pi pair<pair<int,int>,pair<int,int> >
using namespace std;
int in(){int x; scanf("%d",&x); return x;}
priority_queue<pi,vector<pi >,greater<pi > >Q;//cost,y,x,slip
int main(void){
   int n,m;
   while(scanf("%d%d",&n,&m),n+m){
      vector<vector<int> > pos(151);
      vector<vector<int> > cos(151);
      int flag[151][11][76] = {0};
      while(Q.size()) Q.pop();
      rep(i,n){
         int x; scanf("%d",&x);
         rep(j,x){
            int _d;
            scanf("%d",&_d);
            pos[i].push_back(_d);
            scanf("%d",&_d);
            cos[i].push_back(_d);
         }
      }

      rep(i,pos[0].size()){
         Q.push(mpi(0,0,i,0));
      }
      rep(i,pos[1].size()){
         if(m != 0){
            Q.push(mpi(0,1,i,1));
         }
      }

      int ans = 0;
      while(Q.size()){
         pi p = Q.top(); Q.pop();
         if(p.f.s == n-1){ans = p.f.f; break;}
         if(p.f.s == n-2 && m > p.s.s){ans = p.f.f; break;}

         if(flag[p.f.s][pos[p.f.s][p.s.f]][p.s.s] == 1) continue;
         flag[p.f.s][pos[p.f.s][p.s.f]][p.s.s] = 1;

         rep(i,pos[p.f.s+1].size()){
            Q.push(mpi(p.f.f+(cos[p.f.s][p.s.f]+cos[p.f.s+1][i])*abs(pos[p.f.s][p.s.f]-pos[p.f.s+1][i]),p.f.s+1,i,p.s.s));
         }

         rep(i,pos[p.f.s+2].size()){
            if(p.s.s < m) Q.push(mpi(p.f.f+(cos[p.f.s][p.s.f]+cos[p.f.s+2][i])*abs(pos[p.f.s][p.s.f]-pos[p.f.s+2][i]),p.f.s+2,i,p.s.s+1));
         }
      }
      printf("%d\n",ans);
   }
   return 0;
}
;dj++){
        if(y+1+dj<n){
          for(int nx=0;nx<k[y+1+dj];nx++){
        c[y+1+dj][j-dj][nx]=min(c[y+1+dj][j-dj][nx],c[y][j][x]+(d[y][x]+d[y+dj+1][nx])*abs(xp[y][x]-xp[y+1+dj][nx]));
          }
        }else{
          ans=min(ans,c[y][j][x]);
        }
      }
    }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Compiler output:
a.cc:26:27: error: stray '#' in program
   26 |       for(int dj=0;dj<=!!j#include<cstdio>
      |                           ^
a.cc: In function 'int main()':
a.cc:26:27: error: expected ';' before 'include'
   26 |       for(int dj=0;dj<=!!j#include<cstdio>
      |                           ^~~~~~~~
      |                           ;
a.cc:26:28: error: 'include' was not declared in this scope
   26 |       for(int dj=0;dj<=!!j#include<cstdio>
      |                            ^~~~~~~
a.cc:26:36: error: 'cstdio' was not declared in this scope; did you mean 'stdin'?
   26 |       for(int dj=0;dj<=!!j#include<cstdio>
      |                                    ^~~~~~
      |                                    stdin
In file included from /usr/include/c++/14/deque:65,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:28:
/usr/include/c++/14/bits/stl_uninitialized.h:70:1: error: expected primary-expression before 'namespace'
   70 | namespace std _GLIBCXX_VISIBILITY(default)
      | ^~~~~~~~~
a.cc:26:43: error: expected ')' before 'namespace'
   26 |       for(int dj=0;dj<=!!j#include<cstdio>
      |          ~                                ^
      |                                           )
In file included from /usr/include/c++/14/bits/requires_hosted.h:31,
                 from /usr/include/c++/14/iostream:38,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_uninitialized.h:70:15: error: expected '=' before '__attribute__'
   70 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:70:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/bits/stl_uninitialized.h:70:14: error: expected ';' before '__attribute__'
   70 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/stl_uninitialized.h:71:1: error: expected primary-expression before '{' token
   71 | {
      | ^
/usr/include/c++/14/bits/stl_deque.h:72:15: error: expected '=' before '__attribute__'
   72 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:72:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/deque:66:
/usr/include/c++/14/bits/stl_deque.h:72:14: error: expected ';' before '__attribute__'
   72 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/stl_deque.h:73:1: error: expected primary-expression before '{' token
   73 | {
      | ^
/usr/include/c++/14/bits/deque.tcc:61:15: error: expected '=' before '__attribute__'
   61 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/deque.tcc:61:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/deque:69:
/usr/include/c++/14/bits/deque.tcc:61:14: error: expected ';' before '__attribute__'
   61 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/deque.tcc:62:1: error: expected primary-expression before '{' token
   62 | {
      | ^
/usr/include/c++/14/deque:82:15: error: expected '=' before '__attribute__'
   82 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/deque:82:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/deque:82:14: error: expected ';' before '__attribute__'
   82 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/deque:83:1: error: expected primary-expression before '{' token
   83 | {
      | ^
/usr/include/c++/14/bits/stl_vector.h:77:15: error: expected '=' before '__attribute__'
   77 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:77:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/queue:63:
/usr/include/c++/14/bits/stl_vector.h:77:14: error: expected ';' before '__attribute__'
   77 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/stl_vector.h:78:1: error: expected primary-expression before '{' token
   78 | {
      | ^
/usr/include/c++/14/bits/stl_bvector.h:68:15: error: expected '=' before '__attribute__'
   68 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_bvector.h:68:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/vector:67:
/usr/include/c++/14/bits/stl_bvector.h:68:14: error: expected ';' before '__attribute__'
   68 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/stl_bvector.h:69:1: error: expected primary-expression before '{' token
   69 | {
      | ^
/usr/include/c++/14/bits/vector.tcc:59:15: error: expected '=' before '__attribute__'
   59 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:59:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/vector:72:
/usr/include/c++/14/bits/vector.tcc:59:14: error: expected ';' before '__attribute__'
   59 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/vector.tcc:60:1: error: expected primary-expression before '{' token
   60 | {
      | ^
/usr/include/c++/14/bits/vector.tcc:1218:15: error: expected '=' before '__attribute__'
 1218 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:1218:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/bits/vector.tcc:1218:14: error: expected ';' before '__attribute__'
 1218 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/vector.tcc:1219:1: error: expected primary-expression before '{' token
 1219 | {
      | ^
/usr/include/c++/14/vector:88:15: error: expected '=' before '__attribute__'
   88 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/vector:88:15: error: expected identifier before '__attribute__'
/usr/include/c++/14/vector:88:14: error: expected ';' before '__attribute__'
   88 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/vector:89:1: error: expected primary-expression before '{' token
   89 | {
      | ^
/usr/include/c++/14/bits/stl_queue.h:65:15: error: expected '=' before '__attribute__'
   65 | namespace std _GLIBCXX_VISIBILITY(default)
      |               ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:65:15: error: expected identifier before '__attribute__'
In file included from /usr/include/c++/14/queue:66:
/usr/include/c++/14/bits/stl_queue.h:65:14: error: expected ';' before '__attribute__'
   65 | namespace std _GLIBCXX_VISIBILITY(default)
      |              ^
      |              ;
/usr/include/c++/14/bits/stl_queue.h:66:1: error: expected primary-expression before '{' token
   66 | {
      | ^
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683:
/usr/include/math.h:34:1: error: expected unqualified-id before string constant
   34 | __BEGIN_DECLS
      | ^~~~~~~~~~~~~
In file included from a.cc:29:
/usr/include/c++/14/cmath:83:8: error: expected unqualified-id before string constant
   83 | extern "C++"
      |        ^~~~~
a.cc:37:7: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   37 | int in(){int x; scanf("%d",&x); return x;}
      |       ^~
a.cc:37:7: note: remove parentheses to default-initialize a variable
   37 | int in(){int x; scanf("%d",&x); return x;}
      |       ^~
      |       --
a.cc:37:7: note: or replace parentheses with braces to value-initialize a variable
a.cc:37:9: error: a function-definition is not allowed here before '{' token
   37 | int in(){int x; scanf("%d",&x); return x;}
      |         ^
a.cc:38:1: error: 'priority_queue' was not declared in this scope
   38 | priority_queue<pi,vector<pi >,greater<pi > >Q;//cost,y,x,slip
      | ^~~~~~~~~~~~~~
a.cc:30:1: note: 'std::priority_queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
   29 | #include<cmath>
  +++ |+#include <queue>
   30 | #define REP(i,a,n) for(int i = a;i < n;i++)
a.cc:38:18: error: expected primary-expression before ',' token
   38 | priority_queue<pi,vector<pi >,greater<pi > >Q;//cost,y,x,slip
      |                  ^
a.cc:38:19: error: 'vector' was not declared in this scope
   38 | priority_queue<pi,vector<pi >,greater<pi > >Q;//cost,y,x,slip
      |                   ^~~~~~
a.cc:30:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
   29 | #include<cmath>
  +++ |+#include <vector>
   30 | #define REP(i,a,n) for(int i = a;i < n;i++)
a.cc:38:29: error: expected primary-expression before '>' token
   38 | priority_queue<pi,vector<pi >,greater<pi > >Q;//cost,y,x,slip
      |                             ^
a.cc:38:30: error: expected primary-expression before ',' token
   38 | priority_queue<pi,vector<pi >,greater<pi > >Q;//cost,y,x,slip
      |                              ^
a.cc:38:44: error: expected primary-expression before '>' token
   38 | priority_queue<pi,vector<pi >,greater<pi > >Q;//cost,y,x,slip
      |                                            ^
a.cc:38:45: error: 'Q' was not declared in this scope
   38 | priority_queue<pi,vector<pi >,greater<pi > >Q;//cost,y,x,slip
      |                                             ^
a.cc:39:15: error: a function-definition is not allowed here before '{' token
   39 | int main(void){
      |