Skip to content

Commit

Permalink
수리공 항승
Browse files Browse the repository at this point in the history
  • Loading branch information
yewon-yw authored Aug 4, 2022
1 parent 7497c34 commit 83531db
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions greedy_algorithm/1449.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> pipe;

int main() {
int n, l, p, cnt = 1;
cin >> n >> l;
for (int i = 0; i < n; i++) {
cin >> p;
pipe.push_back(p);
}
sort(pipe.begin(), pipe.end());
int tape = pipe.at(0) + l;
for (int i = 0; i < n; i++) {
if (pipe.at(i) < tape) continue;
else {
tape = pipe.at(i) + l;
cnt++;
}
}
cout << cnt << "\n";
}

0 comments on commit 83531db

Please sign in to comment.