Skip to content

Commit 1e80abf

Browse files
authored
Add files via upload
1 parent 1defa07 commit 1e80abf

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <queue>
4+
#include <algorithm>
5+
using namespace std;
6+
7+
struct study {
8+
int start, end;
9+
bool operator<(const study& other) const {
10+
return start < other.start;
11+
}
12+
};
13+
14+
int main() {
15+
ios::sync_with_stdio(false);
16+
cin.tie(nullptr);
17+
18+
int N;
19+
cin >> N;
20+
vector<study> lectures(N);
21+
for (int i = 0; i < N; i++) {
22+
cin >> lectures[i].start >> lectures[i].end;
23+
}
24+
25+
sort(lectures.begin(), lectures.end()); // 시작 시간 기준 정렬
26+
27+
priority_queue<int, vector<int>, greater<int>> pq; // 끝나는 시간 최소 힙
28+
29+
for (auto& lec : lectures) {
30+
if (!pq.empty() && pq.top() <= lec.start) {
31+
pq.pop(); // 기존 강의실 재사용 가능
32+
}
33+
pq.push(lec.end); // 새 강의실 추가 또는 기존 강의실 갱신
34+
}
35+
36+
cout << pq.size(); // 최소 강의실 수
37+
return 0;
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
int main() {
8+
freopen_s(new FILE*, "input.txt", "r", stdin);
9+
ios::sync_with_stdio(false);
10+
cin.tie(nullptr);
11+
12+
int N, K, a,b;
13+
14+
cin >> N >> K;
15+
vector<vector<int>> input(N + 1, vector<int>(2, 0));
16+
vector<vector<int>> V(N + 1, vector<int>(K + 1, 0));
17+
input[0][0] = input[0][1] = 0;
18+
19+
for (int i = 1; i <= N;i++) {
20+
cin >> input[i][1] >> input[i][0]; // weight:1, value:0
21+
}
22+
sort(input.begin(), input.end());
23+
24+
for (int i = 0; i <= N;i++) {
25+
for (int j = 0; j <= K;j++) {
26+
if (i == 0 || j == 0){
27+
V[i][j] = 0;
28+
}
29+
else if (input[i][1] <= j) {
30+
V[i][j] = max(V[i - 1][j], input[i][0] + V[i - 1][j - input[i][1]]);
31+
}
32+
else {
33+
V[i][j] = V[i - 1][j];
34+
}
35+
}
36+
}
37+
38+
39+
cout << V[N][K];
40+
41+
return 0;
42+
}

0 commit comments

Comments
 (0)