-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask4.cpp
More file actions
91 lines (90 loc) · 2.49 KB
/
Task4.cpp
File metadata and controls
91 lines (90 loc) · 2.49 KB
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
#include <iostream>
using namespace std;
class Workshop{
public:
int start_time;
int duration;
int end_time;
};
class Available_Workshops{
public:
int numWorkshops;
Workshop arr[];
Available_Workshops(){};
};
Available_Workshops* initialize(int start_time[],int duration[],int n){
Available_Workshops* aw1 = new Available_Workshops();
aw1->numWorkshops=n;
for(int i = 0 ; i < n ; i++){
aw1->arr[i].start_time = start_time[i];
aw1->arr[i].duration = duration[i];
aw1->arr[i].end_time = start_time[i] + duration[i];
}
return aw1;
}
int CalculateMaxWorkshops(Available_Workshops* ptr){
int count = ptr->numWorkshops,index;
Workshop arr2[count],temp2;
for(int i= count-1; i >= 0; i--){
temp2.start_time = -1;
temp2.end_time = -1;
index=-1;
for(int j = 0;j<count;j++){
if(temp2.start_time == ptr->arr[j].start_time ){
if(temp2.end_time<ptr->arr[j].end_time){
temp2 = ptr->arr[j];
index= j;
}
}
if(temp2.start_time<ptr->arr[j].start_time){
temp2 = ptr->arr[j];
index = j;
}
}
ptr->arr[index].start_time = -1;
ptr->arr[index].duration = -1;
ptr->arr[index].end_time = -1;
arr2[i] = temp2;
}
int max = 0,temp;
for (int i = 0; i < count; i++)
{
int k=i;
temp = 1;
for(int j = i ; j< count-1;j++ ){
//cout<<"i = "<< i <<" K = "<< k <<" j ="<< j <<endl;
//cout<<arr2[k].end_time<<" : "<<arr2[j+1].start_time<<endl;
if(arr2[k].end_time <= arr2[j+1].start_time){
temp++;
k=j+1;
}
//cout<<"temp : "<<temp<<" max : "<<max<<endl;
//cout<<endl;
}
if(temp>max){
max = temp;
}
/*cout<<endl;
cout<<"---------------------------------------------";
cout<<endl;*/
}
return max;
}
int main(){
int N=6;
cin>>N;
int startime[N];//={1,3,0,5,5,8};
int duration[N];//={1,1,6,2,4,1};
for(int i = 0; i < N; i++){
cin>>startime[i];
}
cout<<endl;
for(int i = 0; i < N; i++){
cin>>duration[i];
}
Available_Workshops* aw2;
aw2 = initialize(startime,duration,N);
cout<<"max : "<<CalculateMaxWorkshops(aw2)<<endl;
//CalculateMaxWorkshops(aw2);
return 0;
}