Language: C++

#include<iostream>
#include<algorithm>
using namespace std;

int z(int x){
	if(x<0)return -x;
	return x;
}

int main(){
while(1){
	const long long int INF=1000000000000000000;
	long long int n,m,k;
	static long long int a[1002],b[152][1002],dp[152][1002][102];
	for(int i=0;i<152;i++)for(int j=0;j<1002;j++)for(k=0;k<102;k++)dp[i][j][k]=INF;
	scanf("%d%d",&n,&m);
	if(n==0&&m==0)break;
	for(int i=1;i<=n;i++){
		scanf("%d",&k);
		for(int j=0;j<k;j++){
			scanf("%d",&a[j]);
			scanf("%d",&b[i][a[j]]);
			for(int c=0;c<=m;c++){
				if(i==1)dp[i][a[j]][c]=0;
				else {
					for(int l=0;l<1002;l++){
						if(dp[i-1][l][c]!=INF){
							dp[i][a[j]][c]=min(dp[i][a[j]][c],dp[i-1][l][c]+z(l-a[j])*(b[i][a[j]]+b[i-1][l]));
						}
						if(c!=0){
							if(dp[i-2][l][c-1]!=INF){
								dp[i][a[j]][c]=min(dp[i][a[j]][c],dp[i-2][l][c-1]+z(l-a[j])*(b[i][a[j]]+b[i-2][l]));
							}
						}
					}
				}
			}
		}
	}
	int ret=INF;
	for(int i=0;i<1002;i++)for(int j=0;j<=m;j++)ret=min(ret,dp[n][i][j]);
	printf("%d\n",ret);
}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:40:17: warning: overflow in conversion from 'long long int' to 'int' changes value from '1000000000000000000' to '-1486618624' [-Woverflow]
   40 |         int ret=INF;
      |                 ^~~
a.cc:41:60: error: no matching function for call to 'min(int&, long long int&)'
   41 |         for(int i=0;i<1002;i++)for(int j=0;j<=m;j++)ret=min(ret,dp[n][i][j]);
      |                                                         ~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:41:60: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   41 |         for(int i=0;i<1002;i++)for(int j=0;j<=m;j++)ret=min(ret,dp[n][i][j]);
      |                                                         ~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:41:60: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   41 |         for(int i=0;i<1002;i++)for(int j=0;j<=m;j++)ret=min(ret,dp[n][i][j]);
      |                                                         ~~~^~~~~~~~~~~~~~~~~