Created
July 17, 2016 13:49
-
-
Save Jack-Saleem/d13a89447606dfa118ba46ecbcbb3d13 to your computer and use it in GitHub Desktop.
codeforces 368A SerejaandCoatRack program in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Scanner; | |
public class SerejaandCoatRack | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner z=new Scanner(System.in); | |
int n=z.nextInt(); | |
int d=z.nextInt(); | |
int[] a = new int[n]; | |
for(int i=0;i<n;i++) | |
a[i]=z.nextInt(); | |
int m=z.nextInt(); | |
Arrays.sort(a); | |
int sum=0; | |
if(a.length>=m){ | |
for(int i=0;i<m;i++) | |
sum+=a[i]; | |
System.out.println(sum); | |
} else { | |
for(int i=0;i<n;i++) | |
sum+=a[i]; | |
System.out.println(sum-((m-n)*d)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment