Language: C++

#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define INF 1<<29
#define MAX 1e5
using namespace std;
typedef signed long long int;

int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];

void solve(){
 cin>>n>>m;
 ZERO(sum);
 FOR(i,m) cin>>p[i];
 FOR(i,n-1) cin>>a[i]>>b[i]>>c[i];
 FOR(i,m) p[i]--;
 FOR(i,m-1){
  sum[max(p[i],p[i+1])]--;
  sum[min(p[i],p[i+1])]++;
 }
 int ans=min(sum[0]*a[0],sum[0]*b[0]+c[0]);
 FOR(i,n-1){
  sum[i+1]+=sum[i];
  ans+=max(sum[i+1]*a[i+1],sum[i+1]*b[i+1]+c[i+1]);
 }
 cout<<ans<<endl;
}

int main(){
 solve();
 return 0;
}

Compiler output:
a.cc:9:26: error: declaration does not declare anything [-fpermissive]
    9 | typedef signed long long int;
      |                          ^~~
a.cc:7:13: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    7 | #define MAX 1e5
      |             ^~~
a.cc:11:11: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |           ^~~
a.cc:7:13: error: could not convert '1.0e+5' from 'double' to 'long unsigned int'
    7 | #define MAX 1e5
      |             ^~~
      |             |
      |             double
a.cc:11:11: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |           ^~~
a.cc:7:13: error: size of array 'p' has non-integral type 'double'
    7 | #define MAX 1e5
      |             ^~~
a.cc:11:11: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |           ^~~
a.cc:7:13: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    7 | #define MAX 1e5
      |             ^~~
a.cc:11:18: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                  ^~~
a.cc:7:13: error: could not convert '1.0e+5' from 'double' to 'long unsigned int'
    7 | #define MAX 1e5
      |             ^~~
      |             |
      |             double
a.cc:11:18: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                  ^~~
a.cc:7:13: error: size of array 'a' has non-integral type 'double'
    7 | #define MAX 1e5
      |             ^~~
a.cc:11:18: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                  ^~~
a.cc:7:13: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    7 | #define MAX 1e5
      |             ^~~
a.cc:11:25: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                         ^~~
a.cc:7:13: error: could not convert '1.0e+5' from 'double' to 'long unsigned int'
    7 | #define MAX 1e5
      |             ^~~
      |             |
      |             double
a.cc:11:25: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                         ^~~
a.cc:7:13: error: size of array 'b' has non-integral type 'double'
    7 | #define MAX 1e5
      |             ^~~
a.cc:11:25: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                         ^~~
a.cc:7:13: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    7 | #define MAX 1e5
      |             ^~~
a.cc:11:32: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                                ^~~
a.cc:7:13: error: could not convert '1.0e+5' from 'double' to 'long unsigned int'
    7 | #define MAX 1e5
      |             ^~~
      |             |
      |             double
a.cc:11:32: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                                ^~~
a.cc:7:13: error: size of array 'c' has non-integral type 'double'
    7 | #define MAX 1e5
      |             ^~~
a.cc:11:32: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                                ^~~
a.cc:7:13: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
    7 | #define MAX 1e5
      |             ^~~
a.cc:11:41: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                                         ^~~
a.cc:7:13: error: could not convert '1.0e+5' from 'double' to 'long unsigned int'
    7 | #define MAX 1e5
      |             ^~~
      |             |
      |             double
a.cc:11:41: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                                         ^~~
a.cc:7:13: error: size of array 'sum' has non-integral type 'double'
    7 | #define MAX 1e5
      |             ^~~
a.cc:11:41: note: in expansion of macro 'MAX'
   11 | int n,m,p[MAX],a[MAX],b[MAX],c[MAX],sum[MAX];
      |                                         ^~~