#include <bits/stdc++.h>
//Soltan Cristian
#define fri(a, b) for (int i = (a); i < (b); ++i)
#define frj(a, b) for(int j = a; j < b; j++)
#define frk(a, b) for(int k = a; k < b; k++)
#define frm(a, b, i) for(int i = b; i >= a; i--)
#define ll long long
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define pb push_back
#define st first
#define nd second
#define sz(x) (int)x.size()
#define rall(x) x.rbegin(), x.rend()
#define ct(x) cout << x
#define cts(x) cout << x << ' '
#define ctn(x) cout << x << '\n'
#define Y cout << "YES" << '\n'
#define N cout << "NO" << '\n'
using namespace std;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using ml = map<ll, ll>;
using vii = vector<vector<int>>;
using vll = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <typename T>void read(T n, vector<T> &a){fri(0, n){cin >> a[i];}}
template<typename T>void print(T n, T m, vector<vector<T>> &dp){fri(0, n){ct('\n');frj(0, m){ct(setw(5));cts(dp[i][j]);}}}
const int mxa = 100019;
// string __fname = "invector"; ifstream in(__fname + ".in"); ofstream out(__fname + ".out");
// #define cin in
// #define cout out
void solve(){
int n;
cin >> n;
vi a(n), b(n);
fri(0, n){
cin >> a[i] >> b[i];
}
frj(0, 30){
fri(0, n){
if(a[i] > b[i]){
if(i < n - 1){
if(a[i] - b[i] > 0 && (a[i] - b[i]) % 2 == 0){
a[i + 1] += (a[i] - b[i]) / 2;
a[i] = b[i];
}
else if(a[i] - b[i] > 0 && b[i] > 0){
a[i + 1] += (a[i] - b[i] + 1)/ 2;
a[i] = b[i] - 1;
}
}
if(i == n - 1){
if(a[i] - b[i] > 0 &&(a[i] - b[i]) % 2 == 0){
a[0] += (a[i] - b[i]) / 2;
a[i] = b[i];
}
else if(a[i] - b[i] > 0 && b[i] > 0){
a[0] += (a[i] - b[i] + 1)/ 2;
a[i] = b[i] - 1;
}
}
}
}
}
fri(0, n){
if(a[i] != b[i]){
N;
return;
}
}
Y;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); ct(fixed); ct(setprecision(2));
// int t;
// cin >> t;
// while(t--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |