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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
#include <iostream>

int main()
{
   int iDeliveriesCount = 0;
   int iMaxPosition = 0;
   int iMaxTimeUnit = 0;

   int iFirstEliminatedDelieverIndex = -1;
   int iLeastNumberOfElimination = 0;
   int iFinalLeastNumberOfElimination = 99999;
   
   scanf("%d", &iDeliveriesCount);

   int** aiDeliveriesArray = new int* [iDeliveriesCount];

   for (int i = 0; i < iDeliveriesCount; i++)
   {
       aiDeliveriesArray[i] = new int[5];
   }

   for( int i = 0; i < iDeliveriesCount; i++ )
   {
       scanf( "%d %d %d", 
              &aiDeliveriesArray[i][0],
              &aiDeliveriesArray[i][1], 
              &aiDeliveriesArray[i][2] );

       if( iMaxTimeUnit < aiDeliveriesArray[i][2] )
       {
           iMaxTimeUnit = aiDeliveriesArray[i][2];
       }

       if( iMaxPosition < aiDeliveriesArray[i][1])
       {
           iMaxPosition = aiDeliveriesArray[i][1];
       }

       aiDeliveriesArray[i][3] = 0;
       aiDeliveriesArray[i][4] = 0;
   }

   for (int o = 0; o < iDeliveriesCount; o++)
   {
       for (int i = 0; i < iDeliveriesCount; i++)
       {
           for (int j = 0; j < 5; j++)
           {
               aiDeliveriesArray[i][3] = 0;
           }
       }

       for (int iTimeUnit = 0; iTimeUnit < iMaxTimeUnit + iMaxPosition; iTimeUnit++)
       {
           for (int i = 0; i < iDeliveriesCount; i++)
           {
               if (aiDeliveriesArray[i][2] <= iTimeUnit)
               {
                   if (aiDeliveriesArray[i][4] == 0)
                   {
                       aiDeliveriesArray[i][3]++;
                   }

                   for (int j = 0; j < iDeliveriesCount; j++)
                   {
                       if (i != j
                           && aiDeliveriesArray[i][0] != aiDeliveriesArray[j][0]
                           && aiDeliveriesArray[i][1] == aiDeliveriesArray[j][3]
                           && aiDeliveriesArray[i][3] == aiDeliveriesArray[j][1]
                           && aiDeliveriesArray[i][4] != 1 )
                       {
                           aiDeliveriesArray[j][4] = 1;
                       }
                   }
               }
           }
       }

       iLeastNumberOfElimination = 0;

       for (int i = 0; i < iDeliveriesCount; i++)
       {
           if (aiDeliveriesArray[i][4] == 1)
           {
               iLeastNumberOfElimination++;
           }
       }

       for (int i = iDeliveriesCount-1; i >= 0; i--)
       {
           if( aiDeliveriesArray[i][4] == 1 && ( iFirstEliminatedDelieverIndex == -1 || iFirstEliminatedDelieverIndex != i) )
           {
               aiDeliveriesArray[i][4] = 0;
               iFirstEliminatedDelieverIndex = i;
               break;
           }
       }

       if( iLeastNumberOfElimination < iFinalLeastNumberOfElimination )
       {
           iFinalLeastNumberOfElimination = iLeastNumberOfElimination;
       }
   }

   std::cout << iFinalLeastNumberOfElimination;

   return 0;
}