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

 

15922번: 아우으 우아으이야!!

N개의 선분을 모두 그렸을 때, 수직선 위에 그어진 선분 길이의 총합을 출력한다아아어으잉에애야우아으아이아야아아아아아아이야!!!

www.acmicpc.net

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
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <utility>
#include <unordered_map>
#include <map>
#include <queue>
#include <stack>
using namespace std;
// 아우으 우아으이야!! 15922
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<pair<intint>> line;
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        line.push_back(make_pair(x, y));
    }
    int temp_x = line.front().first;
    int temp_y = line.front().second;
    int total = temp_y - temp_x;
    for (int i = 1; i < N; i++) {
        int next_x = line[i].first;
        int next_y = line[i].second;
        if (next_x <= temp_y && next_y <= temp_y) {
            continue;
        }
        else if (next_x <= temp_y && next_y >= temp_y) {
            total += next_y - temp_y;
            temp_x = temp_y;
            temp_y = next_y;
        }
        else {
            total += next_y - next_x;
            temp_x = next_x;
            temp_y = next_y;
        }
    }
    cout << total << endl;
}
cs

+ Recent posts