#include <bits/stdc++.h>
#define ve vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define si(v) (int)v.size()
#define en '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e5 + 228;
const int big = 1e9;
int n, a[N], k, pr[N];
int main(){
iostream::sync_with_stdio(false); cin.tie(0); ios_base::sync_with_stdio(false); cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
cin >> n, k;
for (int i = 1; i <= n - 1; i++){
int l, r, x;
cin >> l >> r >> x;
a[l] = x;
}
int ans = 0;
for (int i = 1; i <= n; i++) pr[i] = max(pr[i - 1], a[i]);
for (int i = 1; i <= n - 1; i++) if (pr[i] - i >= k) ans++;
cout << ans;
return 0;
}
/*
5 2
1 2 1
2 3 2
3 4 1
4 5 1
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:23:16: warning: right operand of comma operator has no effect [-Wunused-value]
23 | cin >> n, k;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |