[BaekJoon] #5063 - TGN [Java][C++]
[BaekJoon] #5063 - TGN [Java][C++]
1. 아이디어
광고를 하지 않았을 때의 수익과 광고를 했을 때 수익에서 광고 비용을 뺀 것을 비교하면 광고를 할지 말지를 판단할 수 있다.
2. 복잡도
| 접근 | 시간 | 공간 |
|---|---|---|
| 풀이 | $O(T)$ | $O(1)$ |
($T$ = 테스트 케이스 수)
3. 코드
풀이 [Java][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
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
while (n-- > 0) {
st = new StringTokenizer(br.readLine());
int r = Integer.parseInt(st.nextToken());
int e = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
if (r > e - c) {
bw.write("do not advertise\n");
} else if (r < e - c) {
bw.write("advertise\n");
} else {
bw.write("does not matter\n");
}
}
bw.flush();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
while (n--) {
int r, e, c;
cin >> r >> e >> c;
if (r > e - c) {
cout << "do not advertise\n";
} else if (r < e - c) {
cout << "advertise\n";
} else {
cout << "does not matter\n";
}
}
}
This post is licensed under CC BY 4.0 by the author.