結果
| 問題 | 
                            No.1120 Strange Teacher
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kg_curry57
                         | 
                    
| 提出日時 | 2020-07-22 21:47:15 | 
| 言語 | C++17(gcc12)  (gcc 12.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,939 bytes | 
| コンパイル時間 | 10,712 ms | 
| コンパイル使用メモリ | 280,492 KB | 
| 最終ジャッジ日時 | 2025-01-12 02:32:26 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 26 WA * 1 | 
ソースコード
#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}
const double PI = acos(-1);
constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}
class Task{
public:
    void solve(istream& in, ostream& out){
        int N;
        in>>N;
        lint sa = 0, sb = 0;
        vc<int> A(N), B(N);
        REP(i, N) in>>A[i], sa += A[i];
        REP(i, N) in>>B[i], sb += B[i];
        if(N==1){
            if(sa<=sb) out<<sb-sa<<'\n';
            else out<<"-1\n";
            return;
        }else if(N==2){
            if(sa==sb) out<<abs(A[0]-B[0])<<'\n';
            else out<<"-1\n";
            return;
        }else if(sb>sa or (sa-sb)%(N-2)!=0){
            out<<"-1\n";
            return;
        }
        bool ok = true;
        lint x = (sa-sb) / (N-2);
        REP(i, N){
            if(abs(A[i]-B[i])>x) ok = false;
        }
        if(ok) out<<x<<'\n';
        else out<<"-1\n";
    }
};
int main(){
    istream& in(cin);
    ostream& out(cout);
    ios_base::sync_with_stdio(false);
    in.tie(nullptr), out.tie(nullptr);
    Task solver;
    solver.solve(in, out);
    return 0;
}
            
            
            
        
            
kg_curry57