Submission #342140

# Submission time Handle Problem Language Result Execution time Memory
342140 2021-01-01T13:00:47 Z VodkaInTheJar Fortune Telling 2 (JOI14_fortune_telling2) C++14
0 / 100
2 ms 364 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'

using namespace std;

const int maxn = 2e5 + 3; 

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

void solve()
{
	long long ans = 0;
	for (int i = 1; i <= n; i++)
	{
		vector <int> v;
		for (int j = 1; j <= k; j++)
		if (t[j] >= max(a[i].first, a[i].second))
		v.push_back(j);
		
		int groups = 1; 
		for (int j = 0; j < (int)v.size()-1; j++)
		for (int p = v[j] + 1; p < v[j+1]; p++)
		if (t[p] >= min(a[i].first, a[i].second))
		{
			groups++;
			continue;
		}
		
		int first = -1, last = -1; 
		for (int j = 1; j <= k; j++)
		if (t[j] >= min(a[i].first, a[i].second))
		{
			if (t[j] >= max(a[i].first, a[i].second))
			first = 2; 
				
			else 
			first = 1; 
			
			break;
		}
		
		for (int j = k; j >= 1; j--)
		if (t[j] >= min(a[i].first, a[i].second))
		{
			if (t[j] >= max(a[i].first, a[i].second))
			last = 2; 
				
			else 
			last = 1; 
			
			break;
		}
		
		if (first == -1)
		{
			ans += (long long)a[i].first;
			continue;
		}
		
		if (a[i].first < a[i].second)
		{
			if (((int)v.size() - groups) % 2 == 0)
			{
				if (first == 2)
				ans += (long long)a[i].second;
					
				else 
				{
					if (last == 1)
					ans += (long long)a[i].second;
						
					else 
					ans += (long long)a[i].first;
				}
			}
				
			else 
			{
				if (first == 1)
				ans += (long long)a[i].second;
					
				else
				{
					if (last == 1)
					ans += (long long)a[i].second;
					
					else 
					ans += (long long)a[i].first;
				}
			}
		}
		
		else 
		{
			if (((int)v.size() - groups) % 2 == 0)
			{
				if (last == 1)
				ans += (long long)a[i].first;
					
				else 
				ans += (long long)a[i].second;
			}
			
			else
			ans += (long long)a[i].second;
		}
	}
	
	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 Incorrect 2 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -