[BOJ] 1758 알바생 강호

Time Lapse :NONE

1758.cpp

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
32
33
34
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

#define MAXSIZE 100000
int N;
long long num;
vector<long long> arr;
long long ans=0;

int main(void)
{
cin>>N;
for(int i=0;i<N;i++)
{
cin>>num;
arr.push_back(num);
}
sort(arr.begin(),arr.end(),greater<int>());
for(long long i=0;i<arr.size();i++)
{
num=arr[i]-i;
if(num<=0)
continue;
ans+=num;
}
cout<<ans<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/1758/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.