AOAPC:Chapter1Example1 (UVa 11292)

#include "bits/stdc++.h"
using namespace std;

int main(int argc, char const *argv[]) {
  int n, m;
  while (scanf("%d%d", &n, &m), n || m) {
    int dir[20050] = { 0 };
    int abl[20050] = { 0 };
    for (size_t i = 0; i < n; ++i)
      scanf("%d", &dir[i]);
    for (size_t i = 0; i < m; ++i)
      scanf("%d", &abl[i]);
    sort(dir, dir + n);
    sort(abl, abl + m);
    int cost = 0, OKdra = 0;
    for (size_t i = 0; i < m && OKdra < n; ++i)
      if (dir[OKdra] <= abl[i]) { cost += abl[i]; OKdra +=1; }
    if (OKdra < n) puts ("Loowater is doomed!");
    else printf("%d\n", cost);
  }
  return 0;
}

你可能感兴趣的:(Algorithm,ACM-00)