Go: ///
// File:  0579.go
// Author: ymiyamoto
//
// Created on Mon Mar 19 18:46:50 2018
//
package main

import (
	"fmt"
)

var D, N int

type cloth struct {
	A, B, C int
}

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	fmt.Scan(&D, &N)
	thermals := make([]int, D+1)

	for i := 1; i <= D; i++ {
		fmt.Scan(&thermals[i])
	}

	clothes := make([]cloth, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&clothes[i].A, &clothes[i].B, &clothes[i].C)
	}

	dp := make([][]int, D+1)
	for i := range dp {
		dp[i] = make([]int, N)
	}

	for i := 1; i < D; i++ {
		for j := 0; j < N; j++ {
			for k := 0; k < N; k++ {
				t1 := thermals[i]
				t2 := thermals[i+1]
				if clothes[j].A <= t2 && t2 <= clothes[j].B && clothes[k].A <= t1 && t1 <= clothes[k].B {
					dp[i+1][j] = max(dp[i+1][j], dp[i][k]+abs(clothes[j].C-clothes[k].C))
				}
			}
		}
	}

	val := 0
	for _, v := range dp[D] {
		val = max(val, v)
	}

	fmt.Println(val)
}

C++: 
#include<iostream>

using namespace std;

int calc_abso(int a,int b){
    int abso;
    if(a>=b){
        abso=a-b;
    }else if(a<b){
        abso=b-a;
    }
    return abso;
}

struct WEAR{
    int min;        //適す最高気温(下限)
    int max;        //適す最高気温(上限)
    int looks;      //派手さ
};

int dp[256][256]={{0}};    //[日数][服の種]    //値は派手さの絶対値の合計（一番大きいものを最終的に取るように）


int main (void){
    int D,N;
    WEAR status[256];
    int tempe[256];

    cin >> D >> N;

    for(int i=0;i<D;i++){
        cin >> tempe[i];
    }
    for(int i=0;i<N;i++){
        cin >> status[i].min >> status[i].max >> status[i].looks;
        //cout << status[i].min << status[i].max << status[i].looks << endl;
    }

    for(int i=1;i<D;i++){
        cout << "###DBG" << i;
        for(int j=0;j<N;j++){
            cout << "\tbef:" << dp[i][j];
            if((status[j].min<=tempe[j])&&(status[j].max>=tempe[j])){      //この服が今日適しているか？
                int MAX_tortal=-1;    //(前日の服との差+それまで)の最大値
                for(int k=0;k<N;k++){   //前日の服
                    if(dp[i][k]!=-1){
                        int THIS_tortal=calc_abso(status[j].looks , status[k].looks)+dp[i][k];
                        //cout<< "\tadd" << status[k].looks;
                        //cout << "###DBG" << endl;
                        if(THIS_tortal>MAX_tortal){
                            MAX_tortal=THIS_tortal;
                        }
                    }
                }
                dp[i][j]+=MAX_tortal;
            }else{
                dp[i][j]=-1;
            }
            cout << "\taft:" << dp[i][j] << "/";
        }
        cout << endl;
    }

    int LAST_MAX_tortal=-1;
    for(int i=0;i<N;i++){
        if(dp[D-1][i]>LAST_MAX_tortal){
            LAST_MAX_tortal=dp[D-1][i];
        }
    }

    cout << LAST_MAX_tortal << endl;


    return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 1000000001
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
int dp[200][200];//0,up:::1,down
int main(){
      int n,d,t[200],a[200],b[200],c[200];
      cin>>n>>d;
      REP(i,n)cin>>t[i];
      REP(i,d){
            cin>>a[i]>>b[i]>>c[i];
      }
      memset(dp,-1,sizeof(dp));
      REP(i,d){
            if(a[i]<=t[1]&&t[1]<=b[i]){
//                  cout<<a[i]<<" "<<b[i]<<endl;
                  REP(j,d){
                        if(a[j]<=t[0]&&t[0]<=b[j]){
//                              cout<<i<<" "<<j<<endl;
                              dp[1][i]=max(dp[1][i],abs(c[i]-c[j]));
                        }
                  }
            }
      }
//      REP(i,d)cout<<dp[1][i]<<" ";
//      cout<<endl;
      for(int i=2;i<=n;i++){
            REP(j,d){
                  if(t[i]<a[j]||b[j]<t[i])continue;
                  REP(k,d){
                        dp[i][j]=max(dp[i][j],dp[i-1][k]+abs(c[k]-c[j]));
                  }
            }
      }
      int ans=0;
      REP(i,d)ans=max(ans,dp[n-1][i]);
      cout<<ans<<endl;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

int DP[201][201];

int main(int argc, const char * argv[]) {
    int D, N;
    cin >> D >> N;
    vector<int> T(D), A(N), B(N), C(N);
    for (int d = 0; d < D; ++d) {
        cin >> T[d];
    }
    for (int n = 0; n < N; ++n) {
        cin >> A[n] >> B[n] >> C[n];
    }
    for (int n = 0; n < N; ++n) {
        if (T[0] >= A[n] && T[0] <= B[n]) {
            DP[0][n] = 0;
        } else {
            DP[0][n] = -INF;
        }
    }
    for (int d = 1; d < D; ++d) {
        for (int n = 0; n < N; ++n) {
            if (T[d] >= A[n] && T[d] <= B[n]) {
                for (int m = 0; m < N; ++m) {
                    DP[d][n] = max(DP[d][n], DP[d-1][m]+abs(C[n]-C[m]));
                }
            } else {
                DP[d][n] = -INF;
            }
        }
    }
    int Res = -INF;
    for (int n = 0; n < N; ++n) {
        Res = max(Res, DP[D-1][n]);
    }
    cout << Res << endl;

    return 0;
}

C++: #include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int D, N, T[212], A[212], B[212], C[212];
int memo[212][212], ans;

int dp(int d, int b)
{
	if (memo[d][b] != -1) { return memo[d][b]; }
	if (d == 0) { return memo[d][b] = 0; }
	int res = 0;
	rep(i, N)
	{
		if (A[i] <= T[d - 1] && T[d - 1] <= B[i])
		{
			memo[d - 1][i] = dp(d - 1, i) + abs(C[b] - C[i]);
			if (d == D) { memo[d - 1][i] -= abs(C[b] - C[i]); }
			res = std::max(res, memo[d - 1][i]);
		}
	}
	return memo[d][b] = res;
}

int main()
{
	memset(memo, -1, sizeof(memo));
	in >> D >> N;
	rep(i, D) { in >> T[i]; }
	rep(i, N) { in >> A[i] >> B[i] >> C[i]; }

	rep(i, N) { ans = std::max(ans, dp(D, i)); }

	out << ans << std::endl;
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int d,n;
  int degree[205];
  int clothes[200][3];
  int i,j,k;
  int dp[205][205]={};

  cin>>d>>n;
  rep(i,d)
    cin>>degree[i];
  rep(i,n)
    cin>>clothes[i][0]>>clothes[i][1]>>clothes[i][2];

  rep(j,n)
    if(clothes[j][0] > degree[0] || degree[0] > clothes[j][1])
      dp[0][j]=-1;

  for(i=1;i<d;i++)
    rep(j,n){
      if(clothes[j][0] > degree[i] || degree[i] > clothes[j][1]){
	dp[i][j]=-1;
	continue;
      }
      int m=0;
      rep(k,n)
	if(dp[i-1][k] >= 0)
	  m=max(m,dp[i-1][k]+abs(clothes[k][2]-clothes[j][2]));
      dp[i][j]=m;   
    }

  int ans=0;
  rep(j,n)
    ans=max(ans,dp[d-1][j]);
  cout<<ans<<endl;

}