-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGreedy-PP5.c
More file actions
39 lines (39 loc) · 664 Bytes
/
Greedy-PP5.c
File metadata and controls
39 lines (39 loc) · 664 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
#include<stdio.h>
void sort(int a[],int n)
{
int t;
for(int i=0;i<n;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}
int main()
{
int n,gift,min=0,max=0,temp=0;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&gift);
sort(a,n);
for(int i=0;i<n-(gift*temp);i++)
{
temp++;
min+=a[i];
}
temp=0;
for(int i=n-1;i>=(gift*temp);i--)
{
temp++;
max+=a[i];
}
printf("%d\n%d",min,max);
}