답안 #47694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47694 2018-05-06T10:11:10 Z square1001 Fireworks (APIO16_fireworks) C++14
0 / 100
7 ms 7468 KB
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, M, p[300009], c[300009], deg[300009]; vector<long long> v[300009];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N >> M;
	long long sum = 0;
	for (int i = 1; i < N + M; i++) {
		cin >> p[i] >> c[i];
		deg[--p[i]]++;
		sum += c[i];
	}
	for (int i = N + M - 1; i >= 1; i--) {
		if (i >= N) {
			v[i].push_back(c[i]);
			v[i].push_back(c[i]);
		}
		else {
			sort(v[i].begin(), v[i].end());
			for (int j = 0; j < deg[i] - 1; j++) v[i].pop_back();
			v[i][v[i].size() - 1] += c[i];
			v[i][v[i].size() - 2] += c[i];
		}
		v[p[i]].insert(v[p[i]].end(), v[i].begin(), v[i].end());
	}
	sort(v[0].begin(), v[0].end());
	for (int i = 0; i < v[0].size(); i++) {
		sum -= (v[0][i] - (i == 0 ? 0 : v[0][i - 1])) * (v[0].size() - i - 1);
	}
	cout << sum << '\n';
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:30:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v[0].size(); i++) {
                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7416 KB Output is correct
2 Incorrect 7 ms 7416 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 7468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7416 KB Output is correct
2 Incorrect 7 ms 7416 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7416 KB Output is correct
2 Incorrect 7 ms 7416 KB Output isn't correct
3 Halted 0 ms 0 KB -