QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#800810#8866. Drying Laundryphtniit#WA 244ms4400kbC++141.5kb2024-12-06 15:50:352024-12-06 15:50:36

Judging History

This is the latest submission verdict.

  • [2024-12-06 15:50:36]
  • Judged
  • Verdict: WA
  • Time: 244ms
  • Memory: 4400kb
  • [2024-12-06 15:50:35]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

using pii = pair<int, int>;
using vi = vector<int>;
using i64 = long long;
using B = bitset<300030>;

struct S {
  int d;
  int one, two;
  int wst;
};
int main() {
  int n, q;
  cin >> n >> q;
  vector<S> vt(n+1);
  i64 sum = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d %d", &vt[i].d, &vt[i].two, &vt[i].one);
    sum += vt[i].d;
  }
  sort(vt.begin()+1, vt.end(), [&](auto x, auto y){ return x.one < y.one; });
  for (int i = n; i > 0; --i) {
    vt[i].wst = vt[i].two;
    if (i < n) {
      vt[i].wst = max(vt[i].wst, vt[i+1].wst);
    }
  }
  vector<pii> opt;
  const i64 lim = 300000;
  if (sum <= lim) {
    opt.emplace_back(sum, vt[1].wst);
  }
  B dp;
  dp[0] = 1;
  i64 sum2 = 0;
  for (int i = 1; i <= n; ++i) {
    sum -= vt[i].d;
    sum2 += vt[i].d;
    dp |= dp << vt[i].d;
    int bst = dp._Find_next((sum2+1) / 2 - 1);
    if (bst + sum <= lim) {
      int rig = 0;
      if (i < n) {
        rig = vt[i+1].wst;
      }
      opt.emplace_back(bst + sum, max(vt[i].one, rig));
    }
  }
  sort(opt.begin(), opt.end());
  for (int i = 1; i < opt.size(); ++i) {
    opt[i].second = min(opt[i].second, opt[i-1].second);
  }
  while (q--) {
    int len;
    scanf("%d", &len);
    pii e{len, lim+10};
    auto it = upper_bound(opt.begin(), opt.end(), e);
    if (it == opt.begin()) {
      puts("-1");
    } else {
      --it;
      cout << it->second << "\n";
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 244ms
memory: 4400kb

input:

30000 300000
2 255945072 661001220
2 68592698 870026391
2 297602072 943696446
2 423786358 574645263
2 178914703 647767179
2 198609024 717883631
2 167020579 942479667
2 63119081 995866587
2 347306369 881413517
2 58674847 601956876
2 110801873 707995015
2 155453326 765668358
2 438060979 649128264
2 20...

output:

-1
780402504
-1
882630795
-1
-1
694190157
535268040
-1
-1
822796154
867163401
-1
-1
787724542
-1
-1
843406425
-1
608088477
-1
678487355
611519637
956002698
-1
-1
691135882
-1
-1
812320879
-1
677850117
-1
537706551
-1
893747900
786791412
-1
-1
715094556
-1
810021220
724602450
950858613
686685989
-1
-...

result:

wrong answer 2nd lines differ - expected: '780386172', found: '780402504'