QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134267#2281. BnPCYarema#WA 0ms3452kbC++171.4kb2023-08-03 16:06:142023-08-03 16:06:16

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-03 16:06:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3452kb
  • [2023-08-03 16:06:14]
  • 提交

answer

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

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int INF = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	LL n, p;
	cin >> n >> p;
	map<string, int> m;
	FOR (i, 0, n)
	{
		string s;
		cin >> s;
		int x;
		cin >> x;
		m[s] = x;
	}
	int k;
	cin >> k;
	map<string, int> m2;
	map<string, int> cnt;
	FOR (i, 0, k)
	{
		string s;
		int x;
		cin >> s >> x;
		if (m2.count(s)) m2[s] = max(m2[s], x);
		else m2[s] = x;
		cnt[s]++;
	}
	LL need = 0;
	for (auto [s, x] : m2)
		need += max(0, x - m[s]);
	
	if (need >= p)
	{
		cout << 0 << '\n';
		return 0;
	}
	p -= need;
	LL ans = 0;
	vector<LL> v;
	for (auto [s, x] : m2)
	{
		LL y = LL(x + 1) * cnt[s];
		v.PB(y);
	}
	sort(ALL(v), greater());
	n = min(LL(SZ(v)), p);
	FOR (i, 0, n)
		ans += v[i];
	
	int mxc = 0;
	for (auto [s, x] : cnt)
		mxc = max(mxc, x);
	RFOR (i, n, 0)
	{
		if (v[i] < mxc)
		{
			ans -= v[i];
			ans += mxc;
		}
	}
	p -= n;
	cout << ans + p * mxc << '\n';
	
	
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3452kb

input:

3 14
THISISTHEONE 8
B 0
C 0
8
THISISTHEONE 10
C 0
B 1
B 0
THISISTHEONE 0
C 1
THISISTHEONE 0
THISISTHEONE 0

output:

80

result:

wrong answer 1st lines differ - expected: '82', found: '80'