1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<stdio.h>
#include "krazki.h"
#include<message.h>
#include<algorithm>
using namespace std;
long long  *rura, *klocki, *ile,*dziura;
int main()
{
	if(MyNodeId()==0)

	{    
    int n=PipeHeight(),m = NumberOfDiscs();
    rura= new long long [n];
    klocki= new long long [m];
    ile=new long long [m];
    dziura=new long long[m];
    rura[0]=HoleDiameter(1);
    for (int i =1;i<n;i++)
    {
	rura[i]=HoleDiameter(i+1);
	if(rura[i-1]< rura[i]) rura[i] = rura[i-1];
    }
    klocki[0]= DiscDiameter(1);
    ile[0]=1;
    int k=0;
    for (int i=1;i<m;i++)
    {
	int a = DiscDiameter(i+1);

	if(a>klocki[k])
	{
	    k++;
	    klocki[k] = a;
	    ile[k]=1;
	}
	else
	{
	    ile[k]++;
	}
    }
    k++;
    long long cur=0,res=0, prevStop =-1;
    for (int i = k-1;i>=0;i--)
    {
	long long val = klocki[i];
	while(rura[cur] >=val && cur<n)
	{
	    cur++;
	}
    	cur--;
	dziura[i] = cur - prevStop- ile[i];
	prevStop=cur;
	
    }
    long long sum=0;
    for (int i =0;i<k-1;i++)
    {
	sum-=dziura[i];
	if(sum<0) sum=0;
    }
    printf("%lld\n", max(0LL,dziura[k-1]-sum+1));

    delete [] rura;
    delete [] klocki;
    delete [] ile;
    delete [] dziura;
	}

}