-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWood cutter.cpp
More file actions
44 lines (43 loc) · 982 Bytes
/
Wood cutter.cpp
File metadata and controls
44 lines (43 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <string>
#include <iomanip>
#include <cstring>
#include <utility>
using namespace std;
int main() {
int n;
cin >> n;
pair<int, int> trees[n];
int sum =2;
int space=0;
for(int i=0;i <n;i++){
cin >> trees[i].first;
cin >> trees[i].second;
}
if(n<2)
sum=n;
else
space = trees[1].first - trees[0].first;
for(int i=1; i<n-1 ;i++){
if(space > trees[i].second){
sum++;
space = trees[i+1].first - trees[i].first;
}
else{
if(trees[i+1].first-trees[i].first > trees[i].second){
sum++;
space = trees[i+1].first - trees[i].first - trees[i].second;
}
else
space = trees[i+1].first - trees[i].first;
}
}
cout << sum;
return 0;
}