#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
vector<pair<int,int>> seg;
int n, h;
int findp(int x1, int y1, int x2, int y2){
return (h-y1)*(x2-x1)/(y2-y1)+x1;
}
signed main(){
fastio
cin >> n >> h;
vector<pair<int,int>> v;
for(int i = 0;i < n;i++){
int x,y;
cin >> x >> y;
v.push_back({x,y});
}
for(int i = 2;i < n-1;i+=2){
seg.push_back({findp(v[i-1].first,v[i-1].second,v[i].first,v[i].second),findp(v[i].first,v[i].second,v[i+1].first,v[i+1].second)});
}
sort(seg.begin(),seg.end(),[&](pair<int,int> a, pair<int,int> b){
return a.second < b.second;
});
int lst = -1e18, ans = 0;
for(auto [a,b] : seg){
cout << a << " " << b << "\n";
if(lst >= a) continue;
else lst = b, ans++;
}
cout << ans << "\n";
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:30:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | for(auto [a,b] : seg){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |