답안 #335916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335916 2020-12-14T08:51:35 Z VodkaInTheJar 운세 보기 2 (JOI14_fortune_telling2) C++14
4 / 100
3000 ms 1772 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'

using namespace std;

const int maxn = 2e5 + 3;

int n, k;
int a[maxn], b[maxn];
int t[maxn];
void read()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	cin >> a[i] >> b[i];
	
	for (int i = 1; i <= k; i++)
	cin >> t[i];
}

int tr[maxn * 4];

void merge(int v)
{
	tr[v] = max(tr[v * 2], tr[v * 2 + 1]);
}

void build(int v, int l, int r)
{
	if (l == r)
	{
		tr[v] = t[l];
		return;
	}
	
	int mid = (l + r) / 2;
	build(v * 2, l, mid);
	build(v * 2 + 1, mid + 1, r);
	
	merge(v); 
}

int first, second;
void f(int v, int l, int r)
{
 	if (tr[v] < first)
	return;
	
	if (l == r)
	{
		swap(first, second);
		return;
	}
	
	int mid = (l + r) / 2; 
	f(v * 2, l, mid);
	f(v * 2 + 1, mid + 1, r);
}

void solve()
{
	build(1, 1, k);
	
	long long ans = 0;
	for (int i = 1; i <= n; i++)
	{
		first = a[i], second = b[i];
		f(1, 1, k);
		
		ans += first;
	}
	
	cout << ans << endl; 
}

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

	read();
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 7 ms 364 KB Output is correct
4 Correct 7 ms 364 KB Output is correct
5 Correct 8 ms 364 KB Output is correct
6 Correct 6 ms 364 KB Output is correct
7 Correct 7 ms 364 KB Output is correct
8 Correct 8 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 5 ms 364 KB Output is correct
11 Correct 8 ms 364 KB Output is correct
12 Correct 6 ms 396 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 7 ms 364 KB Output is correct
4 Correct 7 ms 364 KB Output is correct
5 Correct 8 ms 364 KB Output is correct
6 Correct 6 ms 364 KB Output is correct
7 Correct 7 ms 364 KB Output is correct
8 Correct 8 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 5 ms 364 KB Output is correct
11 Correct 8 ms 364 KB Output is correct
12 Correct 6 ms 396 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 696 ms 1004 KB Output is correct
15 Correct 2709 ms 1488 KB Output is correct
16 Execution timed out 3093 ms 1772 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 7 ms 364 KB Output is correct
4 Correct 7 ms 364 KB Output is correct
5 Correct 8 ms 364 KB Output is correct
6 Correct 6 ms 364 KB Output is correct
7 Correct 7 ms 364 KB Output is correct
8 Correct 8 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 5 ms 364 KB Output is correct
11 Correct 8 ms 364 KB Output is correct
12 Correct 6 ms 396 KB Output is correct
13 Correct 7 ms 384 KB Output is correct
14 Correct 696 ms 1004 KB Output is correct
15 Correct 2709 ms 1488 KB Output is correct
16 Execution timed out 3093 ms 1772 KB Time limit exceeded
17 Halted 0 ms 0 KB -