結果

問題 No.2603 Tone Correction
ユーザー TairitsuMeowTairitsuMeow
提出日時 2024-01-12 21:47:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,156 bytes
コンパイル時間 2,984 ms
コンパイル使用メモリ 170,988 KB
実行使用メモリ 15,560 KB
最終ジャッジ日時 2024-01-12 21:47:44
合計ジャッジ時間 4,310 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,800 KB
testcase_01 AC 3 ms
9,800 KB
testcase_02 AC 3 ms
9,800 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 33 ms
15,432 KB
testcase_24 AC 34 ms
15,432 KB
testcase_25 AC 34 ms
15,432 KB
testcase_26 AC 33 ms
15,432 KB
testcase_27 AC 34 ms
15,432 KB
testcase_28 AC 33 ms
15,432 KB
testcase_29 AC 34 ms
15,432 KB
testcase_30 AC 33 ms
15,432 KB
testcase_31 AC 33 ms
15,432 KB
testcase_32 AC 34 ms
15,432 KB
testcase_33 AC 3 ms
9,800 KB
testcase_34 AC 27 ms
15,432 KB
testcase_35 AC 27 ms
15,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Problem: No.2603 Tone Correction
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2603
// Memory Limit: 512 MB
// Time Limit: 2000 ms

#include<bits/stdc++.h>
#define debug(x) cerr<<(#x)<<" "<<(x)<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe; 
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=1e6+9;
ll n,m,a[N],b[N],c[N],suf[N];
bool Med;
int main(){
	cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
	n=read(),m=read();
	rep(i,1,n)a[i]=read();
	rep(i,1,n)b[i]=read();
	rep(i,1,n)b[i]=b[i]-a[i];
	rep(i,1,n)c[i]=b[i]-b[i-1];
	rep(i,1,n)b[i]=c[i];
	ll ans1=0,ans2=0;
	rep(i,1,n)b[i]=(b[i]+m)%m;
	sort(b+1,b+n+1);
	per(i,n,1)suf[i]=suf[i+1]+(m-b[i]);
	ll ans=1e18,sum=0;
	rep(i,0,n)ans=min(ans,max(sum,suf[i+1])),sum+=b[i+1];
	write(ans);
	return 0;
}
0