// No.586 ダブルブッキング // https://yukicoder.me/problems/no/586 // #include #include using namespace std; int solve(int P1, int P2, int N); int main() { int P1, P2, N; cin >> P1 >> P2 >> N; int res = solve(P1, P2, N); cout << res << endl; } int solve(int P1, int P2, int N) { int res = 0; unordered_map occupied; int room; for (auto i = 0; i < N; i++) { cin >> room; if (occupied.find(room) != occupied.end()) { res += (P1 + P2); } else { occupied[room] = 1; } } return res; }