結果

問題 No.1120 Strange Teacher
ユーザー kaede2020
提出日時 2020-07-23 16:04:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 69 ms / 1,000 ms
コード長 725 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 169,884 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-23 17:42:21
合計ジャッジ時間 3,779 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//解説AC
int main() {
  long long n;
  cin>>n;
  long long wa_a=0;
  long long wa_b=0;
  vector<long long >a(n),b(n);
  long long kotae=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    wa_a+=a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
    wa_b+=b[i];
  }
  if(n==2){
    if(wa_a-wa_b==0){
      cout<<abs(a[0]-b[0])<<endl;
      return 0;
    }else{
      cout<<-1<<endl;
      return 0;
    }
  }
  kotae=(wa_a-wa_b)/(n-2LL);
  long long wa=0;
  for(int i=0;i<n;i++){
    long long x=b[i]-a[i]+kotae;
    if(x%2==1||x<0){
      cout<<-1<<endl;
      return 0;
    }
    wa+=x;
  }
  if(wa!=2*kotae){
    cout<<-1<<endl;
    return 0;
  }  
  cout<<kotae<<endl;
  return 0;
}
0