# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
875474 | 2023-11-19T20:10:04 Z | Rifal | Simfonija (COCI19_simfonija) | C++14 | 24 ms | 5224 KB |
#include <bits/stdc++.h> using namespace std; #define INF 10000000000000000 #define mod 1000000007 #define endl '\n' int main() { ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); int n, k; cin >> n >> k; long long a[n], b[n]; vector<long long> v; v.push_back(0); long long ans = INF; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; for(int i = 0; i < n; i++) { v.push_back(b[i]-a[i]); } long long siz = v.size(); long long pre[siz] = {}; sort(v.begin(),v.end()); //for(int i = 0; i < v.size(); i++) cout << v[i] << 'k' << endl; pre[0] = abs(v[0]); for(int i = 1; i < v.size(); i++) { pre[i] = pre[i-1] + abs(v[i]); } // for(int i = 0; i < v.size(); i++) cout << pre[i] << 'j' << endl; int indx = lower_bound(v.begin(),v.end(),0)-v.begin(); // cout << indx << 's' << endl; for(long long i = indx+1; i < v.size(); i++) { long long sum = 0, sum2 = 0; sum += (pre[siz-1]-pre[i-1]) - (siz-i) * v[i]; // cout << (pre[siz-1]-pre[i-1]) << ' ' << (siz-i) << ' ' << v[i] << 'f' << endl; sum += ((i-indx)-1ll) * v[i] - (pre[i-1] - pre[indx]); if(indx - 1 >= 0) sum += pre[indx-1] + indx * v[i]; // cout << i << ' ' << sum << ' ' << sum2 << 't' << endl; ans = min(ans,sum); } for(long long i = indx-1; i >= 0; i--) { long long sum = 0, sum2 = 0; sum += pre[i] - (i+1) * v[i]; sum += (indx-(i+1ll)) * v[i] - (pre[indx-1]-pre[i]); if(indx+1 < siz) sum += (pre[siz-1]-pre[indx]) + (siz-indx-1ll) * v[i]; // cout << i << sum << ' ' << sum2 << 'h' << endl; ans = min(ans,sum); } cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 5072 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 5080 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 23 ms | 4936 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 16 ms | 4432 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 23 ms | 5080 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 19 ms | 5064 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 5080 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 5068 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 19 ms | 5224 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |