Contest Duration: ~ (local time) (140 minutes) Back to Home

Submission #3199248

Source Code Expand

Copy
```import java.io.*;
import java.util.*;

public class Main {
FastScanner in;
PrintWriter out;
boolean systemIO = true;

public static void quickSort(int[] a, int from, int to) {
if (to - from <= 1) {
return;
}
int i = from;
int j = to - 1;
int x = a[from + (new Random()).nextInt(to - from)];
while (i <= j) {
while (a[i] < x) {
i++;
}
while (a[j] > x) {
j--;
}
if (i <= j) {
int t = a[i];
a[i] = a[j];
a[j] = t;
i++;
j--;
}
}
quickSort(a, from, j + 1);
quickSort(a, j + 1, to);
}

public void solve() {
int n = in.nextInt();
int x = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = in.nextInt();
}
Arrays.sort(a);
int ans = 0;
int i = 0;
while (i < n) {
if (x >= a[i]) {
ans++;
x -= a[i];
i++;
} else {
break;
}
}
if (i == n && x > 0) {
ans--;
}
out.println(ans);
}

public void run() {
try {
if (systemIO) {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
} else {
in = new FastScanner(new File("input.txt"));
out = new PrintWriter(new File("output.txt"));
}
solve();

out.close();
} catch (IOException e) {
e.printStackTrace();
}
}

class FastScanner {
StringTokenizer st;

FastScanner(File f) {
try {
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

FastScanner(InputStream f) {
}

String nextLine() {
try {
} catch (IOException e) {
return null;
}
}

String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}

int nextInt() {
return Integer.parseInt(next());
}

long nextLong() {
return Long.parseLong(next());
}

double nextDouble() {
return Double.parseDouble(next());
}

}

public static void main(String[] arg) {
new Main().run();
}
}```

#### Submission Info

Submission Time 2018-09-15 21:04:48+0900 A - Candy Distribution Again IakovlevZakhar C++14 (GCC 5.4.1) 0 2288 Byte CE

#### Compile Error

```./Main.cpp:1:1: error: ‘import’ does not name a type
import java.io.*;
^
./Main.cpp:2:1: error: ‘import’ does not name a type
import java.util.*;
^
./Main.cpp:4:1: error: expected unqualified-id before ‘public’
public class Main {
^
```