답안 #106265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
106265 2019-04-17T17:28:27 Z hamzqq9 Simfonija (COCI19_simfonija) C++14
110 / 110
69 ms 3832 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 100000009
#define MOD 998244353
#define N 100005
#define M 2500005
#define LOG 20
#define KOK 300
#define EPS 0.0000001
using namespace std;

int n,k;
int mn=inf,mx=-inf;
int a[N],b[N],ar[N];
ll pre[N];

ll get(int l,int r,int lastng,int cur) {

	umax(lastng,l);
	umin(lastng,n-r);

	ll pos=pre[n-r]-pre[lastng]+(ll)(n-r-lastng)*cur;
	ll neg=pre[lastng]-pre[l]+(ll)(lastng-l)*cur;

	return pos-neg;

}

int main() {

	scanf("%d %d",&n,&k);

	for(int i=1;i<=n;i++) {

		scanf("%d",&a[i]);

	}

	for(int i=1;i<=n;i++) {

		scanf("%d",&b[i]);

		umin(mn,b[i]-a[i]);
		umax(mx,b[i]-a[i]);

	}

	for(int i=1;i<=n;i++) {

		ar[i]=a[i]-b[i];

	}

	sort(ar+1,ar+1+n);

	for(int i=1;i<=n;i++) pre[i]=pre[i-1]+ar[i];

	int l=k,r=0,lastng=n;

	ll ans=(ll)inf*inf;

	for(int i=mn;i<=mx;i++) {

		while(lastng && ar[lastng]+i>=0) lastng--;
		while(l && abs(ar[l]+i)<abs(ar[n-r]+i)) l--,r++;

		umin(ans,get(l,r,lastng,i));

	}

	printf("%lld",ans);

}

Compilation message

simfonija.cpp: In function 'int main()':
simfonija.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~~
simfonija.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
   ~~~~~^~~~~~~~~~~~
simfonija.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&b[i]);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 3696 KB Output is correct
2 Correct 43 ms 3676 KB Output is correct
3 Correct 42 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 3684 KB Output is correct
2 Correct 43 ms 3712 KB Output is correct
3 Correct 43 ms 3708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 3632 KB Output is correct
2 Correct 45 ms 3704 KB Output is correct
3 Correct 42 ms 3704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 2936 KB Output is correct
2 Correct 36 ms 3624 KB Output is correct
3 Correct 49 ms 3784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 3704 KB Output is correct
2 Correct 54 ms 3832 KB Output is correct
3 Correct 45 ms 3704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 3576 KB Output is correct
2 Correct 39 ms 3704 KB Output is correct
3 Correct 48 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 3616 KB Output is correct
2 Correct 43 ms 3704 KB Output is correct
3 Correct 46 ms 3704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 3680 KB Output is correct
2 Correct 67 ms 3832 KB Output is correct
3 Correct 49 ms 3772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 3704 KB Output is correct
2 Correct 40 ms 3704 KB Output is correct
3 Correct 49 ms 3704 KB Output is correct