Submission #102561

# Submission time Handle Problem Language Result Execution time Memory
102561 2019-03-25T23:15:21 Z Ort Simfonija (COCI19_simfonija) C++11
55 / 110
55 ms 796 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);
	int m = 0;
	ll c = 0, nc = 0;
	if(!(k&2)) m = k>>1;
	else m = (k>>1) - 1;
	int mv = a[m];
	for(int i=0;i<k;i++) c += abs(a[i]-mv);
	int om = mv;
	sol = min(sol,c); inc++;
	for(int i=0;i<(n-k);i++) {
		mv = a[m+inc]; inc++;
		nc = c - (abs(om-a[i])) + (abs(mv-a[i+k]));
		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:29:11: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   if(!(k&2==0)) nc -= (mv - om);
          ~^~~
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 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 640 KB Output is correct
2 Correct 37 ms 720 KB Output is correct
3 Correct 33 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 760 KB Output is correct
2 Correct 36 ms 640 KB Output is correct
3 Correct 36 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 768 KB Output is correct
2 Correct 35 ms 768 KB Output is correct
3 Correct 45 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 760 KB Output is correct
2 Correct 38 ms 768 KB Output is correct
3 Correct 39 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 40 ms 716 KB Output is correct
2 Incorrect 55 ms 640 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -