-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathA2.cpp
More file actions
48 lines (41 loc) · 839 Bytes
/
Copy pathA2.cpp
File metadata and controls
48 lines (41 loc) · 839 Bytes
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
#include <fstream>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int main()
{
int n, queueTime, minTime = 0;
fin >> n >> queueTime;
vector<int> arr(n);
for (int i = 0; i < n; i++)
{
fin >> arr[i];
}
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - 1; j++)
{
if (arr[j + 1] < arr[j])
{
swap(arr[j + 1], arr[j]);
}
}
}
minTime += (arr[0] + queueTime);
for (int i = 1; i < n; i++)
{
if (arr[i] < minTime)
{
minTime += queueTime;
}
else
{
minTime += ((arr[i] - minTime) + queueTime);
}
}
fout << minTime;
}