网络流建模求调!
查看原帖
网络流建模求调!
519573
Daniel_yao楼主2024/7/15 15:18
#include<bits/stdc++.h>
#define ll long long
#define key first
#define id second
#define For(i,l,r) for(int i=l;i<=r;++i)
#define FOR(i,r,l) for(int i=r;i>=l;--i)

using namespace std;

const int N = 2e5 + 10;

int n, m, a[N], b[N], c[N], Ans, ans, sum, upd;

vector<pair<int, int> > k;

bool cmp(pair <int, int> x, pair <int, int> y) {
  return x > y;
}

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  For(i,1,n) cin >> a[i];
  For(i,1,m) cin >> b[i];
  For(i,1,m) cin >> c[i], k.push_back({c[i] / b[i], i});
  sort(a + 1, a + n + 1);
  sort(k.begin(), k.end(), cmp);
  For(i,1,m) {
    if(b[i] * n < c[i]) {
      upd += b[i];
    }
    ans += min(b[i] * n, c[i]);
  }
  Ans = ans;
  int j = 1;
  For(i,1,n) {
    sum += a[i];
    ans -= upd;
    for (; k[j].key == n - i; j++) {
      ans += b[k[j].id] * (n - i) - c[k[j].id];
      upd += b[k[j].id];
    }
    Ans = max(Ans, ans);
  }
  cout << Ans << '\n';
  return 0;
}

样例二没过

2024/7/15 15:18
加载中...