Submission #1245532

#TimeUsernameProblemLanguageResultExecution timeMemory
1245532guanexCatfish Farm (IOI22_fish)C++20
6 / 100
56 ms10568 KiB
#include "fish.h"

#include <vector>

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

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  long long ans = 0;
  long long an = 0;
  vector<long long> suff(N+1, 0);
  vector<long long> pref = suff;
  vector<long long> preff = suff;
  vector<long long> suf = suff;
  for(int i = 0; i < (int)W.size(); ++i){
    if(X[i] == 0){
      ans += W[i];
      pref[Y[i]] = W[i];
      suff[Y[i]] = W[i];
    }else{
      an += W[i];
      preff[Y[i]] = W[i];
      suf[Y[i]] = W[i];
    }
  }
  long long mx = max(ans, an);
  if(N==2){
    return mx;
  }
  for(int i = 1; i < N; ++i){
    pref[i] += pref[i-1];
    preff[i] += preff[i-1];
  }
  for(int i = N-1; i >= 0; --i){
    suff[i] += suff[i+1];
    suf[i] += suf[i+1];
  }
  for(int i = 0; i < N; ++i){
    mx = max(mx, pref[i] + suf[i+1]);
    //mx = max(mx, preff[i] + suff[i+1]);
  }
  return mx;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...