結果
問題 | No.2603 Tone Correction |
ユーザー |
|
提出日時 | 2024-01-12 21:50:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 1,158 bytes |
コンパイル時間 | 1,685 ms |
コンパイル使用メモリ | 170,752 KB |
実行使用メモリ | 17,612 KB |
最終ジャッジ日時 | 2024-09-27 21:56:46 |
合計ジャッジ時間 | 4,092 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
// 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]%m; 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; }