Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 라인트레이서
- 컴퓨터 그래픽스
- queue
- 아두이노
- vector
- c++
- directx
- 아두이노 컴파일러
- Array
- 수광 소자
- 아두이노 소스
- 운영체제
- Deque
- C언어
- set
- map
- 시스템프로그래밍
- WinAPI
- Stack
- 통계학
- Algorithm
- Arduino
- html
- arduino compiler
- Visual Micro
- LineTracer
- priority_queue
- 자료구조
- list
- stl
Archives
- Today
- Total
Kim's Programming
1859. 백만 장자 프로젝트 본문
1859. 백만 장자 프로젝트
풀이 방법
가장 어려웠던 문제였다 첨엔 DFS를 이용하여 풀어서 시간초과가 떴다. 하지만 뒤에서부터 하나씩 잡아 팔았을때 가장 비싼 경우를 찾는다.
<코드>
#include <iostream> #include <cstring> using namespace std; long long int* dataArray; long long int answer = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int test_case; int T; cin >> T; for (test_case = 1; test_case <= T; ++test_case) { int n; std::cin >> n; dataArray = new long long int[n]; answer = 0; for (long long int i = 0; i < n; i++) std::cin >> dataArray[i]; int checker = n - 1; for (long long int i = n - 2; i >= 0; i--) { if (dataArray[checker] > dataArray[i]) answer += (dataArray[checker] - dataArray[i]); else checker = i; } delete[] dataArray; std::cout << "#" << test_case << " " << answer << "\n"; } return 0; }
'SW ExpertAcademy > D2' 카테고리의 다른 글
1926. 간단한 369게임 (0) | 2018.12.01 |
---|---|
2007. 패턴 마디의 길이 (0) | 2018.12.01 |
2005. 파스칼의 삼각형 (0) | 2018.12.01 |
2001. 파리 퇴치 (0) | 2018.12.01 |
1989. 초심자의 회문 검사 (0) | 2018.12.01 |