結果

問題 No.2603 Tone Correction
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2024-01-12 22:09:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,581 bytes
コンパイル時間 2,141 ms
コンパイル使用メモリ 206,612 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-12 22:10:23
合計ジャッジ時間 5,093 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 70 ms
6,676 KB
testcase_14 AC 69 ms
6,676 KB
testcase_15 AC 67 ms
6,676 KB
testcase_16 AC 68 ms
6,676 KB
testcase_17 AC 67 ms
6,676 KB
testcase_18 AC 67 ms
6,676 KB
testcase_19 AC 67 ms
6,676 KB
testcase_20 AC 68 ms
6,676 KB
testcase_21 AC 67 ms
6,676 KB
testcase_22 AC 68 ms
6,676 KB
testcase_23 AC 56 ms
6,676 KB
testcase_24 AC 57 ms
6,676 KB
testcase_25 AC 56 ms
6,676 KB
testcase_26 AC 56 ms
6,676 KB
testcase_27 AC 56 ms
6,676 KB
testcase_28 AC 56 ms
6,676 KB
testcase_29 AC 56 ms
6,676 KB
testcase_30 AC 55 ms
6,676 KB
testcase_31 AC 55 ms
6,676 KB
testcase_32 AC 55 ms
6,676 KB
testcase_33 AC 1 ms
6,676 KB
testcase_34 AC 55 ms
6,676 KB
testcase_35 AC 56 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
/*
Take adjacent differences
Then want to do some greedy?
Can do +1 or -1 on one of them.
need to make everything 0
can balance out +1's and -1's.
can do +M or -M free of charge.
either needs +1's or -1's
can try all those options of switchings?
*/
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m; cin >> n>> m;
    vi a(n),b(n);
    for(auto& i : a) cin >> i;
    for(auto& i : b) cin >> i;
    vi c(n);
    c[0]=(a[0]-b[0]+m)%m;
    for(int i=1;i<n;++i) {
        int cur = (a[i]-b[i]+m)%m;
        int prv = (a[i-1]-b[i-1]+m)%m;
        c[i] = (cur-prv+m)%m;
    }
    sort(all(c));
    ll minus = accumulate(all(c),0LL);
    ll plus=0;
    ll ans = minus;
    for(int i=n-1;i>=0;--i) {
        auto cur = c[i];
        if(cur) {
            minus-=c[i];
            plus+=m-c[i];
        }
        ans=min(ans,max(minus,plus));
    }
    cout << ans << '\n';
}
0