#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> N >> M; rep(i, 0, N) cin >> A[i] >> B[i]; rep(i, 0, N + 1) rep(j, 0, 3) dp[i][j] = -infl; chmax(dp[1][2], get(0, 2)); rep(i, 1, N) rep(j, 0, 3) if (-infl <= dp[i][j]) rep(j2, 0, 3) if (j2 <= j) { chmax(dp[i + 1][j2], dp[i][j] + get(i, j2)); } ll ans = -infl; rep(j, 0, 3) chmax(ans, dp[N][j]); cout << ans << endl; }