# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
486177 | idas | Remittance (JOI19_remittance) | C++17 | 1 ms | 332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define sz(x) int((x).size())
using namespace std;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
const int INF=1e9, MOD=1e9+7, mod=998244353;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=1e6+10;
ll n, a[N], b[N];
int main()
{
setIO();
cin >> n;
FOR(i, 0, n)
{
cin >> a[i] >> b[i];
}
set<int> st;
FOR(i, 0, n)
{
if(a[i]-b[i]>1) st.insert(i);
}
bool going=true;
while(going){
going=false;
for(auto x : st){
ll neg=a[x]-b[x];
neg/=2;
a[x]-=neg*2;
int nxt=(x+1)%n;
a[nxt]+=neg;
if(a[nxt]-b[nxt]>1){
st.insert(nxt);
going=true;
}
if(a[x]-b[x]>1){
st.insert(x);
going=true;
}
}
}
FOR(i, 0, n)
{
if(a[i]!=b[i]){
cout << "No";
return 0;
}
}
cout << "Yes";
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |