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 <stdio.h>
#define N 1000000
#define INF 0x3f3f3f3f3f3f3f3fLL
long long min(long long a, long long b) { return a < b ? a : b; }
int solve(int *aa, int *bb, int n, long long k_) {
int i;
long long k, c;
k = k_;
for (i = n - 1; i > 0; i--) {
if (aa[i] - k * 2 > bb[i])
return -1;
k = min(bb[i] - (aa[i] - k * 2), INF);
}
c = bb[0] - (aa[0] + k_ - k * 2);
return c == 0 ? 0 : (c < 0 ? -1 : 1);
}
int main() {
static int aa[N], bb[N];
int n, i, same, zero;
long long lower, upper;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d%d", &aa[i], &bb[i]);
same = 1;
for (i = 0; i < n; i++)
if (aa[i] != bb[i]) {
same = 0;
break;
}
if (same) {
printf("Yes\n");
return 0;
}
zero = 1;
for (i = 0; i < n; i++)
if (bb[i] != 0) {
zero = 0;
break;
}
if (zero) {
printf("No\n");
return 0;
}
lower = 0, upper = INF;
while (upper - lower > 1) {
long long k = (lower + upper) / 2;
if (solve(aa, bb, n, k) <= 0)
lower = k;
else
upper = k;
}
printf(solve(aa, bb, n, lower) == 0 ? "Yes\n" : "No\n");
return 0;
}
Compilation message (stderr)
remittance.c: In function 'main':
remittance.c:27:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
remittance.c:29:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d%d", &aa[i], &bb[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |