QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#530319#7744. ElevatordechancerWA 35ms3912kbC++20912b2024-08-24 16:00:562024-08-24 16:00:56

Judging History

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

  • [2024-08-24 16:00:56]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:3912kb
  • [2024-08-24 16:00:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void solve() {
  int n;
  ll k;
  cin >> n >> k;

  vector p(n, pair(0, 0));
  for (auto& [f, num] : p) {
    int c, w;
    cin >> c >> w >> f;
    num = c * w;
  }
  sort(p.rbegin(), p.rend());

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (p[i].second >= k) {
      ans += p[i].second / k * p[i].first;
      p[i].second %= k;
    }
    if (i == n - 1) {
      if (p[i].second) {
        ans += p[i].first;
      }
      break;
    }
    int j = i;
    ll sum = 0;
    while (j < n and sum <= k) {
      sum += p[j].second;
      j++;
    }
    ans += p[i].first;
    p[j - 1].second = sum - k;
    i = j - 2;
  }

  cout << ans << '\n';
}

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

  int tc;
  cin >> tc;
  while (tc--) {
    solve();
  }

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3784kb

input:

2
4 6
1 1 8
7 2 5
1 1 7
3 2 6
8 1200000
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345

output:

24
100000

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 35ms
memory: 3912kb

input:

5501
8 104
5 2 3
6 2 4
5 2 3
6 2 9
8 2 4
2 1 3
7 2 4
8 2 8
1 290
3 1 1
12 12
6 1 2
1 2 2
1 1 2
1 2 4
6 1 1
1 2 5
6 1 4
4 1 4
6 2 4
6 2 5
4 2 5
4 1 4
5 334
1 1 4
1 2 3
4 2 1
5 1 1
2 1 2
13 218
5 2 3
5 1 4
1 2 1
1 2 5
3 2 2
1 1 3
4 2 2
1 2 5
2 2 1
2 1 5
3 2 1
5 2 1
1 1 4
10 260
7 2 1
5 1 1
5 2 4
6 1 6...

output:

12
1
23
5
6
8
2
4
10
7
2
11
5
11
20
6
5
2
11
6
9
9
2
4
24
7
4
5
3
3
4
5
9
2
6
11
10
12
149
8
11
2
8
9
9
7
6
6
2
8
4
6
11
8
10
12
9
2
5
3
4
10
1
6
3
10
2
8
11
10
7
11
19
9
11
5
11
10
3
10
4
7
16
4
8
6
4
2
7
2
4
3
4
2
7
11
7
4
8
9
14
10
3
7
2
3
10
9
6
3
6
21
9
2
3
4
6
10
4
5
8
6
10
7
1
8
4
8
4
3
3
8
8...

result:

wrong answer 1st lines differ - expected: '9', found: '12'