황찌옹
정리왕옹옹
황찌옹
GitHub Contribution
Loading data ...
  • 분류 전체보기 (158)
    • [ 알고리즘 ] (96)
      • Implementation (24)
      • Brute Force (6)
      • String (4)
      • Greedy (14)
      • DFS, BFS (13)
      • Back Tracking (4)
      • Sort & Binary Search (6)
      • DP (8)
      • Shortest Path (5)
      • Hash (3)
      • Stack, Queue (4)
      • Heap (1)
      • Tree (1)
      • Mathematics (1)
      • Ad-Hoc (1)
      • 기타 (COS Pro, etc) (1)
    • [ 언어 및 문법 ] (23)
      • Python (5)
      • C, C++ (13)
      • SQL (1)
      • 공통 개념(CS) (4)
    • [ Error ] (21)
      • Radiomics Feature Extraction (6)
      • CT Skin Segmentation (12)
      • etc (3)
    • [ Git ] (7)
    • [ 환경 설정 및 기타] (6)
    • [ 공부 ] (2)
      • AI, ML (0)
      • Computer Vision (0)
      • Image Processing (1)
      • QT (0)
      • AWS (1)
      • 의료 (0)
    • [ 포트폴리오 ] (1)
      • 🙋‍♀️자기 소개🙋‍♀️ (1)
      • 프로젝트 (0)
      • 공모전 (0)
      • 자격증 (0)
      • 대내외활동 (0)
      • 논문 (0)
      • 교육 봉사 (0)
    • [ 취준 ] (2)
      • 채용 설명회, 직무 상담 (1)
      • 취준 후기 (1)

블로그 메뉴

  • ❤️깃허브❤️

인기 글

태그

  • OpenCV
  • Visual Studio
  • tensorflow
  • Cloud
  • pyplot
  • QT
  • Anaconda
  • numpy
  • config
  • 씹어먹는C++
  • c++
  • Python
  • git
  • aws
  • configuration
  • SQL
  • 모두의코드
  • cs
  • keras
  • cos pro

최근 댓글

최근 글

전체 방문자
오늘
어제
hELLO · Designed By 정상우.
황찌옹

정리왕옹옹

[ 알고리즘 ]/Greedy

[백준] 11501. 주식

2022. 6. 29. 02:31

 

📌문제

https://www.acmicpc.net/problem/11501

 

🎖️난이도

 

✔️풀이

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <math.h>
#include <tuple>
#include <typeinfo>  // operator typeid

using namespace std;


int T(0);
int N(0);

long long solution(vector<int> day) {
    long long answer(0);
    long long max_val = *max_element(day.begin(), day.end());
    long long max_index(0);

    for (int i = 0; i < N; i++) {
        if (max_val == day[i] && i != N - 1) {
            max_val = *max_element(day.begin() + i + 1, day.end());
            continue;
        }
        else {
            answer += max_val - day[i];
        }
    }

    return answer;
}

int main(void) {

    cin >> T;

    for (int i = 0; i < T; i++) {
        cin >> N;
        vector<int> day(N);
        int sum(0);
        for (int j = 0; j < N; j++) {
            cin >> day[j];
        }
        for (int k = 0; k < N; k++) {
            sum += day[k];
        }

        if (day[0] * N == sum) { cout << 0 << endl; }
        else { cout << solution(day) << endl; }
    }

    return 0;
}

'[ 알고리즘 ] > Greedy' 카테고리의 다른 글

[프로그래머스] 단속카메라  (0) 2022.06.29
[프로그래머스] 구명보트  (0) 2022.06.29
[프로그래머스] 큰 수 만들기  (0) 2022.06.29
[프로그래머스] 체육복  (0) 2022.06.29
[백준] 11497. 통나무 건너뛰기  (0) 2022.06.29
    황찌옹
    황찌옹
    다 정리해버리꺼야

    티스토리툴바