# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
94029 | zeyad49 | Teams (CEOI11_tea) | Java | 2630 ms | 117556 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.io.*;
import java.util.*;
class tea{
static int INF=(int)1e9;
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner();
PrintWriter out=new PrintWriter(System.out);
int n=sc.nextInt();
Integer[]indices=new Integer[n];
int []a=new int [n];
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
indices[i]=i;
}
Arrays.sort(indices,Comparator.comparingInt(i->-a[i]));
int []dp=new int [n+1]; //number of teams
int []nxt=new int [n+1];
int []maxTeam=new int [n+1];
maxTeam[n]=-INF;
for(int i=n-1;i>=0;i--) {
int idx=indices[i];
if(i+a[idx]>n)
dp[i]=-INF;
else {
int best=i+a[idx];
int currMax=Math.max(a[idx],maxTeam[i+a[idx]]);
for(int j=i+a[idx];j<=n;j++)
{
int newMax=Math.max(j-i,maxTeam[j]);
if(dp[j]>dp[best]||(dp[j]==dp[best] && newMax<currMax)) {
best=j;
currMax=newMax;
}
}
nxt[i]=best;
dp[i]=1+dp[best];
maxTeam[i]=currMax;
}
}
out.println(dp[0]);
Queue<Integer> list=new LinkedList();
for(int i=0;i<n;) {
int j=nxt[i];
while(i<j) {
list.add(indices[i]+1);
i++;
}
out.print(list.size());
while(!list.isEmpty())
out.print(" "+list.poll());
out.println();
}
out.close();
}
static class Scanner
{
BufferedReader br;
StringTokenizer st;
Scanner(){
br=new BufferedReader(new InputStreamReader(System.in));
}
Scanner(String fileName) throws FileNotFoundException{
br=new BufferedReader(new FileReader(fileName));
}
String next() throws IOException {
while(st==null || !st.hasMoreTokens())
st=new StringTokenizer(br.readLine());
return st.nextToken();
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException{
return Integer.parseInt(next());
}
long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(next());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(next());
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |