#include #include int main() { int N, * pointsP, * aP, b, flag = 1, max = 0; if (scanf("%d", &N) != 1) { return -1; } pointsP = (int*)malloc(sizeof(int) * 101); aP = (int*)malloc(sizeof(int) * N); if (pointsP == NULL || aP == NULL) { return -1; } for (int i = 0; i < 101; i++) { *(pointsP + i) = 0; } for (int i = 0; i < N; i++) { if (scanf("%d", &*(aP + i)) != 1) { return -1; } } for (int i = 0; i < N; i++) { if (scanf("%d", &b) != 1) { return -1; } *(pointsP + b) += *(aP + i); } max = *(pointsP + 0); for (int i = 0; i < 101; i++) { if (max < *(pointsP + i)) { flag = 0; break; } } if (flag == 1) { printf("YES"); } else { printf("NO"); } free(pointsP); free(aP); pointsP = NULL; aP = NULL; return 0; }