Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 백준 알고리즘
- 주린이
- 2370 c++
- 삼성SW 역량 테스트 기출문제
- 에라토스테네스의 체
- 15651c++
- 삼성 SW역량 테스트
- BFS
- fill함수
- 용어 정리
- DP
- 주식 용어
- 백준 15651
- 프로그래머스
- 백준 2370
- 15651
- Programmers
- 위상정렬
- C++
- 백준
- 삼성 SW 역량 테스트 기출 문제
- DFS
- 백준 1697
- 시장 선거 포스터 c++
- 브루트포스
- 백준알고리즘
- 백트레킹
- MySQL
- backtracking
- 주식 용어 정리
Archives
- Today
- Total
빠켱이
백준 8980번 택배[C++] 본문
#include <iostream>
#include <algorithm>
using namespace std;
struct info {
int sender;
int reciever;
int cnt;
};
info arr[10000];
int capacity[10001] = { 0 };
int n = 0, c = 0, m = 0;
int result = 0;
bool cmp(info a, info b) {
if (a.reciever < b.reciever)return true;
else if (a.reciever == b.reciever)
if (a.sender < b.sender)
return true;
return false;
}
int main() {
scanf("%d %d", &n, &c);
scanf("%d", &m);
for (int i = 0; i < m; i++)
cin >> arr[i].sender >> arr[i].reciever >> arr[i].cnt;
sort(arr, arr + m,cmp); //오름차순 정렬 1.도착지 2.출발지
for (int i = 0; i < m; i++) {
int maxcnt = 0;
for (int j = arr[i].sender; j < arr[i].reciever; j++) //보내는곳부터 받는곳까지
maxcnt = max(capacity[j], maxcnt); //capacity의 최대값을 저장합니다. 박스를 얼마나 넣을 수 있는 확인하기 위해
int val = min(arr[i].cnt, c - maxcnt);
result += val;
for (int j = arr[i].sender; j < arr[i].reciever; j++)
capacity[j] += val; // 이동되면서 해당 공간만큼 할당해주어야 박스가 못 실리겠죠
}
printf("%d", result);
}
'알고리즘 > 백준 알고리즘' 카테고리의 다른 글
백준 2217번 로프[C++] (0) | 2021.03.01 |
---|---|
백준 3053번 택시 기하학[C++] (0) | 2021.03.01 |
백준 1976번 여행 가자[C++] (0) | 2021.02.24 |
백준 17135번 캐슬 디펜스[C++] - 삼성 A형 기출 문제 (0) | 2021.02.24 |
백준 11725번 트리의 부모 찾기[C++] (0) | 2021.02.23 |
Comments