Notice
Recent Posts
Recent Comments
Today
Total
01-11 08:45
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[์œ„ํด๋ฆฌ ์ฑŒ๋ฆฐ์ง€] ๋ถ€์กฑํ•œ ๊ธˆ์•ก ๊ณ„์‚ฐํ•˜๊ธฐ ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[์œ„ํด๋ฆฌ ์ฑŒ๋ฆฐ์ง€] ๋ถ€์กฑํ•œ ๊ธˆ์•ก ๊ณ„์‚ฐํ•˜๊ธฐ

WonderJay 2022. 7. 5. 16:54
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://school.programmers.co.kr/learn/courses/30/lessons/82612

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

๋ฌธ์ œ๋Š” ๋งค์šฐ ๋‹จ์ˆœํ•˜๋‚˜, ์ž๋ฃŒํ˜•์— ์ฃผ์˜ํ•ด์•ผํ•œ๋‹ค.

signed int ์ž๋ฃŒํ˜•์˜ ์ตœ๋Œ€๊ฐ’์€ 2,147,483,647 ์ธ๋ฐ, ํ•ด๋‹น ๋ฌธ์ œ์—์„œ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋Š” ๊ฐ€์žฅ ํฐ ์ˆ˜๋Š” 7,815,625,000 ์œผ๋กœ 

integer ๋ฒ”์œ„๋ฅผ ๋›ฐ์–ด๋„˜๋Š”๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ long long ์ž๋ฃŒํ˜•์„ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

 

[C++]

#include <bits/stdc++.h>
#define fastio cin.tie(0)->sync_with_stdio(0)
#define ll long long

using namespace std;

long long solution(int price, int money, int count)
{
    fastio;
    ll answer = -1;
    ll acc_price = 0;

    for (int i = 1; i <= count; i++)
    {
        acc_price += (price * i);
    }

    return (acc_price - money) >= 0 ? acc_price - money : 0;
}

 

 

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments