# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
100257 | 2019-03-10T07:04:10 Z | pzdba | Simfonija (COCI19_simfonija) | C++14 | 261 ms | 2040 KB |
#include <bits/stdc++.h> using namespace std; long long oo = 1e18; int n, k; int a[100001], b[100001], c[100001], d[100001]; long long solve(int x){ for(int i=1;i<=n;i++) d[i] = c[i]+x; int l = 1, r = n, cnt = 0; while(cnt < k){ cnt++; if(abs(d[l]) > abs(d[r])) d[l] = 0, l++; else d[r] = 0, r--; } long long ans = 0; for(int i=1;i<=n;i++) ans += abs(d[i]); return ans; } 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]); for(int i=1;i<=n;i++) c[i] = a[i]-b[i]; sort(c+1, c+1+n); int lo = 0, hi = 2000000; long long ans = oo; for(int i=0;i<100;i++){ int mid1 = lo + (hi-lo)/3; int mid2 = hi - (hi-lo)/3; long long result1 = solve(mid1); long long result2 = solve(mid2); if(result1 < result2){ ans = min(ans, result1); hi = mid2; } else{ ans = min(ans, result2); lo = mid1; } } lo = 0, hi = 2000000; for(int i=0;i<100;i++){ int mid1 = lo + (hi-lo)/3; int mid2 = hi - (hi-lo)/3; long long result1 = solve(-mid1); long long result2 = solve(-mid2); if(result1 < result2){ ans = min(ans, result1); hi = mid2; } else{ ans = min(ans, result2); lo = mid1; } } printf("%lld\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 96 ms | 1912 KB | Output is correct |
2 | Correct | 120 ms | 1932 KB | Output is correct |
3 | Correct | 95 ms | 1920 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 92 ms | 2012 KB | Output is correct |
2 | Correct | 124 ms | 2036 KB | Output is correct |
3 | Correct | 94 ms | 1912 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 96 ms | 1956 KB | Output is correct |
2 | Correct | 98 ms | 1952 KB | Output is correct |
3 | Correct | 92 ms | 1912 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 214 ms | 1936 KB | Output is correct |
2 | Incorrect | 133 ms | 1912 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 157 ms | 1924 KB | Output is correct |
2 | Correct | 185 ms | 2012 KB | Output is correct |
3 | Incorrect | 261 ms | 1920 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 187 ms | 1920 KB | Output is correct |
2 | Incorrect | 118 ms | 1856 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 193 ms | 1932 KB | Output is correct |
2 | Correct | 139 ms | 1916 KB | Output is correct |
3 | Correct | 181 ms | 2040 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 154 ms | 1844 KB | Output is correct |
2 | Correct | 237 ms | 1932 KB | Output is correct |
3 | Correct | 103 ms | 1920 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 144 ms | 1912 KB | Output is correct |
2 | Correct | 99 ms | 2016 KB | Output is correct |
3 | Correct | 128 ms | 1912 KB | Output is correct |