Submission #102560

#TimeUsernameProblemLanguageResultExecution timeMemory
102560OrtSimfonija (COCI19_simfonija)C++11
110 / 110
56 ms888 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...