답안 #875474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875474 2023-11-19T20:10:04 Z Rifal Simfonija (COCI19_simfonija) C++14
0 / 110
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

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;
      |                            ^~~~
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 5072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 5080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 4936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 4432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 5080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 5064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 5080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 5068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 5224 KB Output isn't correct
2 Halted 0 ms 0 KB -