[SWEA] 4050 재관이의 대량 할인

Time Lapse :13min 5sec

4050.c

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
35
36
37
38
39
40
41
42
43
44
45
//#pragma GCC optimize ("O3")
#define gc() getchar_unlocked()
#define pc(x) putchar_unlocked(x)
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>

int clothes[100000], N;
long answer = 0;

int readINT() {
int N = gc(), ret = 0;
do {
ret = (ret << 3) + (ret << 1) + (N & 0b1111); N = gc();
} while (48 <= N);
return ret;
}
void writeANSWER(int tc) {
long rev = 0, count = 0;
pc(0x23);
while (!(tc % 10)) { count++; tc /= 10; }
while (tc) { rev = (rev << 3) + (rev << 1) + tc % 10; tc /= 10; }
while (rev) { pc(rev % 10 | 0b110000); rev /= 10; }
while (count--) pc(0x30);
count = 0; pc(0x20);
while (!(answer % 10)) { count++; answer /= 10; }
while (answer) { rev = (rev << 3) + (rev << 1) + answer % 10; answer /= 10; }
while (rev) { pc(rev % 10 | 0b110000); rev /= 10; }
while (count--) pc(0x30);
pc(0x0A);
return;
}
int compare(const void *a, const void *b) {
return *(int*)a > *(int*)b ? 1 : -1;
}
int main(int argc, char** argv) {
register int tc = 1, T = readINT();
for (; tc <= T;) {
N = readINT();
for (int i = 0; i < N; i++) clothes[i] = readINT();
qsort(clothes, N, sizeof(int), compare);
for (int i = N - 1; i >= 0; i--) if ((N - i) % 3) answer += clothes[i];
writeANSWER(tc++);
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/4050/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.