Submission #783981

#TimeUsernameProblemLanguageResultExecution timeMemory
783981SoulKnightCatfish Farm (IOI22_fish)C++17
0 / 100
112 ms15932 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define ln '\n' long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { if (N <= 2){ ll r1, r2; r1 = r2 = 0LL; for (int i = 0; i < M; i++){ if (X[i] == 1) r2 += W[i]; else r1 += W[i]; } cout << max(r1, r2) << ln; } else { ll r0, r1; r0 = r1 = 0LL; vector<array<ll, 2>> vec0, vec1; for (int i = 0; i < M; i++){ if (X[i] == 0) {vec0.push_back({Y[i], W[i]}); r1 += W[i];} else {vec1.push_back({Y[i], W[i]}); r0 += W[i];} } if (vec0.empty()) {return r0; } if (vec1.empty()) {return r1;} sort(vec0.begin(), vec0.end()); sort(vec1.begin(), vec1.end()); for (int i = 1; i < vec0.size(); i++) vec0[i][1] += vec0[i-1][1]; for (int i = 1; i < vec1.size(); i++) vec1[i][1] += vec1[i-1][1]; ll ans = r1; array<ll, 2> t; for (auto& p: vec0){ // cout << p[0] << ' ' << p[1] << ln; t = {p[0], -1}; int idx = upper_bound(vec1.begin(), vec1.end(), t) - vec1.begin(); idx--; ll tmp = r1; if (idx >= 0) tmp -= vec1[idx][1]; ans = max(ans, tmp + p[1]); } // cout << ans << ln; return ans; } }

Compilation message (stderr)

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int i = 1; i < vec0.size(); i++) vec0[i][1] += vec0[i-1][1];
      |                         ~~^~~~~~~~~~~~~
fish.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int i = 1; i < vec1.size(); i++) vec1[i][1] += vec1[i-1][1];
      |                         ~~^~~~~~~~~~~~~
fish.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
   61 | }
      | ^
#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...