(あとで)
class GUMIAndSongsDiv1 { public: int maxSongs(vector <int> D, vector <int> tone, int T) { int N=D.size(); VVI dp(N, VI(N+1, 1<<30)); vector<PII> w; REP(i, N) w.PB(MP(tone[i], D[i])); sort(ALL(w)); REP(i, N) D[i]=w[i].second, tone[i]=w[i].first; REP(i, N) { dp[i][0] = 0; dp[i][1] = D[i]; RANGE(n, 2, N+1) { REP(j, i) { dp[i][n] = min(dp[i][n], dp[j][n-1] + D[i] + abs(tone[i]-tone[j])); } } } int ans = 0; REP(i, N) REP(n, N+1) if(dp[i][n]<=T) ans = max(ans, n); return ans; } };