Submission #571197

# Submission time Handle Problem Language Result Execution time Memory
571197 2022-06-01T13:44:29 Z Farhan_HY Simfonija (COCI19_simfonija) C++14
44 / 110
53 ms 20100 KB
#include <bits/stdc++.h>
#define int long long
#define float double
#define pb push_back
#define F first
#define S second
#define T int t; cin >> t; while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
/// Benzema in the best player in the world
const int inf = 8e18;
const int N = 1e6 + 6;
const int M = 1e3 + 3;
const int LOG = 31;
const int mod = 1e9 + 7;
const float pi = atan(1) * 4;
int n, k, a[N], b[N], cnt[2 * N];
vector<int> v;

main()
{
    IOS
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
        cin >> b[i];
    int pos = 0, posn = 0, neg = 0, negn = 0, zn = 0;
    for(int i = 1; i <= n; i++)
    {
        if (a[i] < b[i])
            neg += b[i] - a[i], negn++, cnt[b[i] - a[i]]++;
        else if (a[i] > b[i])
            pos += a[i] - b[i], posn++;
        else
            zn++;
    }
    int x = 0, ans = neg + pos;
    for(int i = 1; i <= 2e6; i++)
    {
        neg -= negn;
        negn -= cnt[i];
        pos += posn + zn;
        posn += zn;
        zn = cnt[i];
        if (ans > neg + pos)
            x = i, ans = neg + pos;
        cnt[i] = 0;
    }
    neg = 0, negn = 0, posn = 0, pos = 0, zn = 0;
    for(int i = 1; i <= n; i++)
    {
        if (b[i] < a[i])
            neg += a[i] - b[i], negn++, cnt[a[i] - b[i]]++;
        else if (b[i] > a[i])
            pos += b[i] - a[i], posn++;
        else
            zn++;
    }
    for(int i = 1; i <= 2e6; i++)
    {
        neg -= negn;
        negn -= cnt[i];
        pos += posn + zn;
        posn += zn;
        zn = cnt[i];
        if (ans > neg + pos)
            x = -i, ans = neg + pos;
        cnt[i] = 0;
    }
    for(int i = 1; i <= n; i++)
        a[i] += x, v.pb(abs(a[i] - b[i]));
    sort(v.begin(), v.end(), greater<int>());
    for(int i = 0; i < k; i++)
        ans -= v[i];
    cout << ans;
}
///use scanf

Compilation message

simfonija.cpp:21:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   21 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 15956 KB Output is correct
2 Correct 14 ms 15900 KB Output is correct
3 Correct 14 ms 15988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 18688 KB Output is correct
2 Correct 39 ms 20020 KB Output is correct
3 Correct 44 ms 20040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 18700 KB Output is correct
2 Correct 42 ms 20100 KB Output is correct
3 Correct 37 ms 20044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 18688 KB Output is correct
2 Correct 44 ms 20048 KB Output is correct
3 Correct 37 ms 20088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 18704 KB Output is correct
2 Correct 46 ms 18636 KB Output is correct
3 Incorrect 36 ms 18664 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 18696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 42 ms 18732 KB Output is correct
2 Incorrect 38 ms 18636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 18600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 18696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 18612 KB Output isn't correct
2 Halted 0 ms 0 KB -