답안 #403696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403696 2021-05-13T11:22:04 Z CursedCode Fireworks (APIO16_fireworks) C++14
0 / 100
2 ms 1740 KB
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
	int N,M,i,j;
	long long a[100000],as = 0,b[100000],x = 1000000000,y = 0,ans = 0,ansl = 1000000000;
	cin >> N >> M;
	for(i = 1;i <= N + M - 1;i++){
		cin >> a[i] >> b[i];
	}
	sort(b + 1,b + M);
	if(M%2 == 1){
		for(i = 1;i <= N + M - 1;i++){
			ans += abs(b[(M + 1)/2] - b[i]);
		}
		cout << ans;
	}
	else{
		long long x = b[M / 2];
		for(i = 1;i <= N + M - 1;i++){
			ans += abs(x - b[i]);
		}
		x = b[M / 2 + 1];
		for(i = 1;i <= N + M - 1;i++){
			as += abs(x - b[i]);
		}
		cout << min(ans,as);
	}
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:8:12: warning: unused variable 'j' [-Wunused-variable]
    8 |  int N,M,i,j;
      |            ^
fireworks.cpp:9:39: warning: unused variable 'x' [-Wunused-variable]
    9 |  long long a[100000],as = 0,b[100000],x = 1000000000,y = 0,ans = 0,ansl = 1000000000;
      |                                       ^
fireworks.cpp:9:54: warning: unused variable 'y' [-Wunused-variable]
    9 |  long long a[100000],as = 0,b[100000],x = 1000000000,y = 0,ans = 0,ansl = 1000000000;
      |                                                      ^
fireworks.cpp:9:68: warning: unused variable 'ansl' [-Wunused-variable]
    9 |  long long a[100000],as = 0,b[100000],x = 1000000000,y = 0,ans = 0,ansl = 1000000000;
      |                                                                    ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1740 KB Output is correct
2 Correct 1 ms 1740 KB Output is correct
3 Incorrect 2 ms 1740 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1740 KB Output is correct
2 Correct 1 ms 1740 KB Output is correct
3 Incorrect 2 ms 1740 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1740 KB Output is correct
2 Correct 1 ms 1740 KB Output is correct
3 Incorrect 2 ms 1740 KB Output isn't correct
4 Halted 0 ms 0 KB -