-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompSubtest1.cpp
More file actions
73 lines (66 loc) · 1.54 KB
/
CompSubtest1.cpp
File metadata and controls
73 lines (66 loc) · 1.54 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
#include<iostream>
using namespace std;
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
/*void swapf(float *xp, float *yp)
{
float temp = *xp;
*xp = *yp;
*yp = temp;
}*/
int main()
{
int t;
cin>>t;
for (size_t z = 0; z < t; z++)
{
int n;
cin>>n;
int s[n],e[n],l[n];
//float r[n];
for (size_t i = 0; i < n; i++)
{
cin>>s[i]>>e[i]>>l[i];
//r[i]=float(s[i])/float(l[i]);
//cout<<r[i]<<"\t";
}
//cout<<endl;
bool swapped;
for (size_t i = 0; i < n-1; i++)
{
swapped = false;
for (size_t j = 0; j < n-i-1; j++)
{
if (l[j] < l[j+1])
{
//swapf(&r[j], &r[j+1]);
swap(&s[j], &s[j+1]);
swap(&e[j], &e[j+1]);
swap(&l[j], &l[j+1]);
swapped = true;
}
}
// IF no two elements were swapped by inner loop, then break
if (swapped == false)
break;
}
/*for (size_t i = 0; i < n; i++)
{
cout<<s[i]<<" "<<e[i]<<" "<<l[i]<<"\n";
}*/
int times=0;
int te=0;
for (size_t i = 0; i < n; i++)
{
te=te-(times* l[i]);
te=te+e[i];
times=times+s[i];
}
cout<<"Case #"<<z+1<<": "<<te<<endl;
}
return 0;
}