Submission #17810832


Source Code Expand

#include <algorithm>
#include <cstdio>
#define INF 1e9
#define eps 1e-6
#define N 400010
#define int long long 
typedef long long ll;
using namespace std;

int n, m, pos;
ll qsum[N], hsum[N], h[N], w[N], d1, d2, d, ans = 1e18, sum;

signed main(){

	scanf("%lld%lld", &n, &m);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &h[i]);
	for(int i = 1; i <= m; i++)
		scanf("%lld", &w[i]);
	sort(h + 1, h + n + 1);
	sort(w + 1, w + m + 1);
	for(int i = 2; i <= n; i += 2)
		qsum[i] = qsum[i - 2] + h[i] - h[i - 1];
	for(int i = n - 1; i >= 1; i -= 2)
		hsum[i] = hsum[i + 2] + h[i + 1] - h[i];
	for(int i = 1; i <= n; i++){
		pos = lower_bound(w + 1, w + m + 1, h[i]) - w, sum = 0;
		if(pos == 1) d = w[pos] - h[i];
		else if(pos == m + 1) d = h[i] - w[pos - 1];
		else if(w[pos] - h[i] > h[i] - w[pos - 1]) d = h[i] - w[pos - 1];
		else d = w[pos] - h[i];
		if(i & 1){
			sum += qsum[i - 1] + hsum[i + 1];
			sum += d;
		}
		else{
			sum += qsum[i - 2] + hsum[i + 2];
			sum += d;
			sum += h[i + 1] - h[i - 1];
		}
		if(ans > sum)
			ans = sum;
	}
	printf("%lld\n", ans);

	return 0;
}

Submission Info

Submission Time
Task E - Transformable Teacher
User HoshizoraZ
Language C++ (GCC 9.2.1)
Score 500
Code Size 1128 Byte
Status AC
Exec Time 93 ms
Memory 7992 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:15:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   15 |  scanf("%lld%lld", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
./Main.cpp:17:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   17 |   scanf("%lld", &h[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
./Main.cpp:19:8: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   19 |   scanf("%lld", &w[i]);
      |   ~~~~~^~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 38
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01_small.txt, random_02_small.txt, random_03_small.txt, random_04_small.txt, random_05_small.txt, random_06_small.txt, random_07_small.txt, random_08_small.txt, random_09_small.txt, random_10_small.txt, random_11_small.txt, random_12_small.txt, random_13_small.txt, random_14_small.txt, random_15_small.txt, random_16_small.txt, random_17_small.txt, random_18_small.txt, random_19_small.txt, random_20_small.txt, random_21_med.txt, random_22_med.txt, random_23_med.txt, random_24_med.txt, random_25_med.txt, random_26_med.txt, random_27_med.txt, random_28_large.txt, random_29_large.txt, random_30_large.txt, random_31_max.txt, random_32_max.txt, random_33_max.txt, random_34_max.txt, random_35_max.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01_small.txt AC 7 ms 1656 KiB
random_02_small.txt AC 1 ms 1756 KiB
random_03_small.txt AC 2 ms 1652 KiB
random_04_small.txt AC 1 ms 1672 KiB
random_05_small.txt AC 1 ms 1692 KiB
random_06_small.txt AC 1 ms 1696 KiB
random_07_small.txt AC 1 ms 1748 KiB
random_08_small.txt AC 1 ms 1752 KiB
random_09_small.txt AC 1 ms 1728 KiB
random_10_small.txt AC 1 ms 1748 KiB
random_11_small.txt AC 1 ms 1744 KiB
random_12_small.txt AC 1 ms 1756 KiB
random_13_small.txt AC 1 ms 1672 KiB
random_14_small.txt AC 1 ms 1704 KiB
random_15_small.txt AC 1 ms 1652 KiB
random_16_small.txt AC 1 ms 1680 KiB
random_17_small.txt AC 3 ms 1752 KiB
random_18_small.txt AC 1 ms 1708 KiB
random_19_small.txt AC 1 ms 1668 KiB
random_20_small.txt AC 1 ms 1700 KiB
random_21_med.txt AC 1 ms 1696 KiB
random_22_med.txt AC 2 ms 1756 KiB
random_23_med.txt AC 1 ms 1672 KiB
random_24_med.txt AC 3 ms 1692 KiB
random_25_med.txt AC 1 ms 1676 KiB
random_26_med.txt AC 1 ms 1656 KiB
random_27_med.txt AC 1 ms 1708 KiB
random_28_large.txt AC 21 ms 2728 KiB
random_29_large.txt AC 73 ms 5840 KiB
random_30_large.txt AC 38 ms 3116 KiB
random_31_max.txt AC 93 ms 7992 KiB
random_32_max.txt AC 90 ms 7972 KiB
random_33_max.txt AC 93 ms 7948 KiB
random_34_max.txt AC 49 ms 7972 KiB
random_35_max.txt AC 60 ms 7956 KiB
sample_01.txt AC 1 ms 1696 KiB
sample_02.txt AC 2 ms 1648 KiB
sample_03.txt AC 2 ms 1660 KiB