Submission #102560

# Submission time Handle Problem Language Result Execution time Memory
102560 2019-03-25T23:10:24 Z Ort Simfonija (COCI19_simfonija) C++11
110 / 110
56 ms 888 KB
#include<iostream>
#include<algorithm>
#define MAX 100020
#define ll long long
 
using namespace std;
 
int n, k, x, inc;
ll sol = 100000000000000000;

int a[MAX];
 
int main() {
	scanf("%d%d", &n, &x); k = n - x;
	for(int i=0;i<n;i++) scanf("%d", &a[i]);
	for(int i=0;i<n;i++) {scanf("%d", &x); a[i]-=x;}
	sort(a, a+n);
	ll m = 0, c = 0, nc = 0, l, r;
	if(k%2) m = k / 2;
	else m = k / 2 - 1;
	int mv = a[m];
	for(int i=0;i<k;i++) c += abs(a[i]-mv);
	ll om = mv;
	sol = min(sol,c); inc++;
	for(int i=0;i<(n-k);i++) {
		mv = a[m+inc]; inc++;
		l = a[i]; r = a[i+k];
		nc = c - (abs(om-l)) + (abs(mv-r));
		if(k%2==0) nc -= (mv - om);
		sol = min(sol,nc);
		c = nc; om = mv;
	}
	printf("%lld", sol);
    return 0;
}

Compilation message

simfonija.cpp: In function 'int main()':
simfonija.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &x); k = n - x;
  ~~~~~^~~~~~~~~~~~~~~~
simfonija.cpp:15:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%d", &a[i]);
                       ~~~~~^~~~~~~~~~~~~
simfonija.cpp:16:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) {scanf("%d", &x); a[i]-=x;}
                        ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 768 KB Output is correct
2 Correct 53 ms 856 KB Output is correct
3 Correct 34 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 640 KB Output is correct
2 Correct 34 ms 888 KB Output is correct
3 Correct 38 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 640 KB Output is correct
2 Correct 32 ms 640 KB Output is correct
3 Correct 32 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 768 KB Output is correct
2 Correct 31 ms 768 KB Output is correct
3 Correct 43 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 768 KB Output is correct
2 Correct 37 ms 748 KB Output is correct
3 Correct 35 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 720 KB Output is correct
2 Correct 56 ms 632 KB Output is correct
3 Correct 39 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 748 KB Output is correct
2 Correct 33 ms 640 KB Output is correct
3 Correct 37 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 640 KB Output is correct
2 Correct 44 ms 760 KB Output is correct
3 Correct 38 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 640 KB Output is correct
2 Correct 34 ms 768 KB Output is correct
3 Correct 49 ms 768 KB Output is correct