Greed

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using std::vector;
using std::sort;
int cmp(const void * x, const void * y) {
    //x < y
    return (*((long long *)(x))) > (*((long long *)(y))) ? 1 : -1;
}
long long a[100005], b[100005];
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)scanf("%lld", &a[i]);
    for (int i = 0; i < n; i++)scanf("%lld", &b[i]);
    //qsort(b, n, sizeof(long long), cmp);
    sort(b, b + n);
    long long sum = 0;
    for (int i = 0; i < n; i++) sum += a[i];
    if (sum > b[n - 1] + b[n - 2]) printf("NO\n");
    else printf("YES\n");
    return 0;
}
View Code

相关文章:

  • 2021-11-02
  • 2021-07-14
  • 2021-06-30
  • 2022-01-25
  • 2021-09-15
  • 2021-11-17
猜你喜欢
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2022-01-27
相关资源
相似解决方案