Submission #335154

# Submission time Handle Problem Language Result Execution time Memory
335154 2020-12-11T09:55:03 Z VodkaInTheJar Fortune Telling 2 (JOI14_fortune_telling2) C++14
4 / 100
3000 ms 1588 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], 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];
}

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], b[i]))
			v.push_back(1);
			
			else 
			if (t[j] >= min(a[i], b[i]))
			v.push_back(2);
		}
		
	    vector <int> v1;
	    int cnt = 1;
	    for (int j = 1; j < (int)v.size(); j++)
	    {
			if (v[j] != v[j-1])
			{
				if (v[j-1] == 1)
				{
					if (cnt % 2 == 1)
					v1.push_back(1);
				}
				
				else 
				if (v1.empty() || v1.back() == 1)
				v1.push_back(2);
				
				cnt = 1; 
			}
			
			else 
			cnt++;
		}
		
		if (!v.empty())
		{
			if (v.back() == 1)
		    {
			    if (cnt % 2 == 1)
			    v1.push_back(1);
		    }
		    
		    else 
		    if (v1.empty() || v1.back() == 1)
		    v1.push_back(2);
		}
		
		int temp;
		if (v1.empty())
		temp = 0;
		
		else
		if (a[i] >= b[i])
		{
			if (v1[0] == 1)
			temp = (int)v1.size();
			
			else 
			temp = (int)v1.size()-1; 
		}
		
		else 
		{
			if (v1[0] == 2)
			temp = (int)v1.size();
			
			else 
			{
				if ((int)v1.size() == 1)
				temp = 1; 
				
				else
				temp = (int)v1.size()-1;
			}
		}
		
		if (temp & 1)
		ans += b[i];
		
		else 
		ans += a[i];
	}
	
	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 2 ms 364 KB Output is correct
2 Correct 7 ms 364 KB Output is correct
3 Correct 12 ms 364 KB Output is correct
4 Correct 13 ms 364 KB Output is correct
5 Correct 12 ms 364 KB Output is correct
6 Correct 14 ms 364 KB Output is correct
7 Correct 6 ms 364 KB Output is correct
8 Correct 8 ms 364 KB Output is correct
9 Correct 6 ms 364 KB Output is correct
10 Correct 8 ms 364 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 7 ms 364 KB Output is correct
13 Correct 6 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 7 ms 364 KB Output is correct
3 Correct 12 ms 364 KB Output is correct
4 Correct 13 ms 364 KB Output is correct
5 Correct 12 ms 364 KB Output is correct
6 Correct 14 ms 364 KB Output is correct
7 Correct 6 ms 364 KB Output is correct
8 Correct 8 ms 364 KB Output is correct
9 Correct 6 ms 364 KB Output is correct
10 Correct 8 ms 364 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 7 ms 364 KB Output is correct
13 Correct 6 ms 364 KB Output is correct
14 Correct 1039 ms 1004 KB Output is correct
15 Execution timed out 3063 ms 1588 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 7 ms 364 KB Output is correct
3 Correct 12 ms 364 KB Output is correct
4 Correct 13 ms 364 KB Output is correct
5 Correct 12 ms 364 KB Output is correct
6 Correct 14 ms 364 KB Output is correct
7 Correct 6 ms 364 KB Output is correct
8 Correct 8 ms 364 KB Output is correct
9 Correct 6 ms 364 KB Output is correct
10 Correct 8 ms 364 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 7 ms 364 KB Output is correct
13 Correct 6 ms 364 KB Output is correct
14 Correct 1039 ms 1004 KB Output is correct
15 Execution timed out 3063 ms 1588 KB Time limit exceeded
16 Halted 0 ms 0 KB -