Submission #875474

#TimeUsernameProblemLanguageResultExecution timeMemory
875474RifalSimfonija (COCI19_simfonija)C++14
0 / 110
24 ms5224 KiB
#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 (stderr)

simfonija.cpp: In function 'int main()':
simfonija.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i = 1; i < v.size(); i++) {
      |                    ~~^~~~~~~~~~
simfonija.cpp:25:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(long long i = indx+1; i < v.size(); i++) {
      |                               ~~^~~~~~~~~~
simfonija.cpp:26:28: warning: unused variable 'sum2' [-Wunused-variable]
   26 |         long long sum = 0, sum2 = 0;
      |                            ^~~~
simfonija.cpp:35:28: warning: unused variable 'sum2' [-Wunused-variable]
   35 |         long long sum = 0, sum2 = 0;
      |                            ^~~~
#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...