-
Notifications
You must be signed in to change notification settings - Fork 0
/
32pdp.afinal.cpp
105 lines (85 loc) · 1.96 KB
/
32pdp.afinal.cpp
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
/* USER: 32pdpu17
LANG: C++
TASK: erasmus*/
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <array>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
//vector and array declaration
int uni[1005];
int out[10005];
array<int, 15> data[10005];
int main()
{
//declaring variables
int n = 0;
int m = 0;
int help = 0;
int j;
//initializing freopen functions
freopen("erasmus.in","r",stdin);
freopen("erasmus.out","w",stdout);
//Scanning and storing the num. of students and the num. of the universities
scanf("%d",&n);
scanf("%d",&m);
//scanning the universities open positions and placing them in a 1D array
for(int i=0;i<=n-1;i++)
{
scanf("%d",&uni[i]);
}
//scanning the student-university data and placing them in a 2D array
for(int i=0;i<=m-1;i++)
{
scanf("%d",&data[i][0]);
scanf("%d",&help);
data[i][1] = help;
data[i][13] = i;
for(int j=2;j<=help+1;j++)
{
scanf("%d",&data[i][j]);
}
}
sort(data, data + m); //Sorting the student-university data
//deciding what student will go to what university
for(int i = m-1; i >= 0; i--)
{
for(int x = 0; x <= data[i][1]-1; x++)
{
if (uni[data[i][x+2]-1] != 0)
{
data[i][12] = data[i][x+2];
uni[data[i][x+2]-1]--;
break;
}
}
}
//Managing the output data
for(int i = 0; i <= m-1; i++)
{
if (data[i][12] == 0)
{
out[data[i][13]] = 0;
}
else
{
out[data[i][13]] = data[i][12];
}
}
//printing output data
for(int i = 0; i <= m-1; i++)
{
if (out[i] == 0)
{
printf("NONE\n");
}
else
{
printf("%d\n",out[i]);
}
}
return 0;
}