Submission #335917

# Submission time Handle Problem Language Result Execution time Memory
335917 2020-12-14T08:56:34 Z VodkaInTheJar Fortune Telling 2 (JOI14_fortune_telling2) C++14
4 / 100
3000 ms 1004 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) >> 1; 
	f((v << 1), l, mid);
	f((v << 1) + 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();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 364 KB Output is correct
3 Correct 7 ms 364 KB Output is correct
4 Correct 7 ms 364 KB Output is correct
5 Correct 7 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 3 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 6 ms 364 KB Output is correct
12 Correct 6 ms 364 KB Output is correct
13 Correct 8 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 364 KB Output is correct
3 Correct 7 ms 364 KB Output is correct
4 Correct 7 ms 364 KB Output is correct
5 Correct 7 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 3 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 6 ms 364 KB Output is correct
12 Correct 6 ms 364 KB Output is correct
13 Correct 8 ms 364 KB Output is correct
14 Correct 695 ms 748 KB Output is correct
15 Correct 2726 ms 908 KB Output is correct
16 Execution timed out 3068 ms 1004 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 364 KB Output is correct
3 Correct 7 ms 364 KB Output is correct
4 Correct 7 ms 364 KB Output is correct
5 Correct 7 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 3 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 6 ms 364 KB Output is correct
12 Correct 6 ms 364 KB Output is correct
13 Correct 8 ms 364 KB Output is correct
14 Correct 695 ms 748 KB Output is correct
15 Correct 2726 ms 908 KB Output is correct
16 Execution timed out 3068 ms 1004 KB Time limit exceeded
17 Halted 0 ms 0 KB -