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
46
47
48
49
50
51
52
53
#include <iostream>

int main() {
    size_t n, k, t; 
    std::cin >> n;
    std::cin >> k;
    std::cin >> t;

    int result = 0; 
    bool at_home = true;
    int work_count = 0;

    for (size_t i = 0; i < n; i++) {
        char input_char;
        std::cin >> input_char;

        int input = input_char - '0';

        if (input == 3 && at_home)
            result++; 

        if (input == 1) {
            work_count++;
            if (at_home) {
                if (k > 0) {
                    // skip
                    k--;
                    result++;
                } else {
                    // commute
                    at_home = false;
                    result -= t;
                }
            }
        }
        
        if (input == 2) {
            work_count++;
            if (at_home && k > 0) {
                // skip
                k--;
                result++;
            }
       }
    }
    
    int magic = n - work_count - 2*t + k;
    if (magic < 1) {
        result = -1;
    }

    std::cout << result << "\n";
}