1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cstdint>
#include <iostream>
#include <algorithm>
#include <set>
#include <math.h>
#include <stdint.h>
#include <fstream>

using namespace std;

int main() {
    int n, c;
    cin >> n >> c;
    int a, w;
    int current_w = 0;
    int ret = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a >> w;
        // cout << c*(w == current_w or current_w == 0) << endl;
        ret += max(0, a - c*(w == current_w or current_w == 0));
        current_w = w;
    }
    cout << ret;
}