QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#693122#9529. Farm ManagementisaunoyaWA 0ms3612kbC++234.0kb2024-10-31 15:34:342024-10-31 15:34:34

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 15:34:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-10-31 15:34:34]
  • 提交

answer


#if defined(local)
#include "./noya/debug.hpp"
#else
#define debug(...) 42
#endif

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
#define rep1(a) for (int i = 0; i < a; i++)
#define rep2(i, a) for (int i = 0; i < a; i++)
#define rep3(i, a, b) for (int i = a; i < b; i++)
#define rep4(i, a, b, c) for (int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define pb emplace_back
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
  x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
  x = x > y ? x : y;
}


#include <cstdint>
using ll = int64_t;
using ull = uint64_t;
namespace noya {
template <class T> constexpr T infty = 0;
template <> constexpr int infty<int> = 1010000000;
template <> constexpr ll infty<ll> = 2020000000000000000;
template <> constexpr unsigned infty<unsigned> = infty<int>;
template <>
constexpr ull infty<ull> = infty<ll>;
template <>
constexpr __int128 infty<__int128> =
    __int128(infty<ll>) * 2000000000000000000;
template <> constexpr double infty<double> = infty<ll>;
template <> constexpr long double infty<long double> = infty<ll>;
} // namespace noya


using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T> using vc = vector<T>;
const int INF = 1010000000;
const ll LNF = 1010000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second

namespace noya {}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N, M;
  cin >> N >> M;
  vector<array<ll, 3>> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i][0] >> A[i][1] >> A[i][2];
  }

  sort(all(A));

  // ll ans = 0;
  // for (int a = 0; a < N; a++) {
  //   ll cur = 0;
  //   ll rem = M;
  //   for (int i = 0; i < N; i++)
  //     if (i != a) {
  //       cur += A[i][0] * A[i][1];
  //       rem -= A[i][1];
  //     }

  //   for (int i = N - 1; i >= 0; i--) {
  //     ll delta = A[i][2] - A[i][1];
  //     if (i == a) {
  //       delta = M;
  //     }
  //     ll take = min(delta, rem);
  //     rem -= take;
  //     cur += A[i][0] * take;
  //   }
  //   cmax(ans, cur);
  // }

  ll cnt = 0, S = 0;
  for (int i = 0; i < N; i++) {
    S += A[i][0] * A[i][1];
    cnt += A[i][1];
  }

  vector<int> take(N);
  for (int i = 0; i < N; i++) {
    take[i] = A[i][2] - A[i][1];
  }

  vector<ll> suf_take(N + 1);

  vector<ll> suf_sum(N + 1);
  for (int i = N - 1; i >= 0; i--) {
    suf_take[i] = suf_take[i + 1] + take[i];
    suf_sum[i] = suf_sum[i + 1] + take[i] * A[i][0];
  }

  ll ans = 0;
  for (int a = 0; a < N; a++) {
    ll cur = S;
    ll rem = M - cnt;
    cur -= A[a][0] * A[a][1];
    rem += A[a][1];
    
    int l = -1, r = N;
    while (r - l > 1) {
      int m = (l + r) / 2;
      ll sum_take = suf_take[m];
      if (m <= a) {
        sum_take += M - take[a];
      }
      if (sum_take >= rem) {
        l = m;
      } else {
        r = m;
      }
    }
    if (l >= 0) {
      ll sum_take = suf_take[l];
      if (l <= a)
        sum_take += M - take[a];
      cur += suf_sum[l] - A[l][0] * (sum_take - rem);
      cmax(ans, cur);
    }
  }
  cout << ans << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

109

result:

ok single line: '109'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

12 62
503792 9 10
607358 1 3
600501 10 10
33249 4 4
774438 6 6
197692 3 6
495807 8 8
790225 5 9
77272 3 8
494819 4 9
894779 3 9
306279 5 6

output:

35204500

result:

ok single line: '35204500'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3500kb

input:

15 32
835418 2 3
178262 1 3
527643 2 2
519710 1 1
774544 3 3
82312 1 1
808199 1 1
809396 1 3
255882 1 3
80467 1 3
874973 1 3
813965 1 2
198275 1 2
152356 1 3
802055 1 1

output:

14600992

result:

wrong answer 1st lines differ - expected: '22000255', found: '14600992'