Submission #468397

#TimeUsernameProblemLanguageResultExecution timeMemory
468397rainliofficialCloud Computing (CEOI18_clo)Java
0 / 100
114 ms9488 KiB
import java.io.*; import java.util.*; public class clo { static int n, m; static Item[] arr; static int[][] computer, work; static long[][] dp; public static void main(String[] args) throws IOException{ BufferedReader file = new BufferedReader(new InputStreamReader(System.in)); //BufferedReader file = new BufferedReader(new FileReader("file.in")); //PrintWriter outfile = new PrintWriter (new BufferedWriter(new FileWriter("clo.out"))); n = Integer.parseInt(file.readLine()); computer = new int[n][3]; int sumCores = 0; for (int i=0; i<n; i++){ StringTokenizer st = new StringTokenizer(file.readLine()); int c = Integer.parseInt(st.nextToken()); int f = Integer.parseInt(st.nextToken()); int e = Integer.parseInt(st.nextToken()); computer[i] = new int[] {c, f, e}; } m = Integer.parseInt(file.readLine()); arr = new Item[n+m]; work = new int[m][3]; for (int i=0; i<m; i++){ StringTokenizer st = new StringTokenizer(file.readLine()); int c = Integer.parseInt(st.nextToken()); int f = Integer.parseInt(st.nextToken()); int e = Integer.parseInt(st.nextToken()); work[i] = new int[] {c, f, e}; arr[n+i] = new Item(c, f, e, 1); // Set order cores to negative, so we just need to sum all item cores to positive } for (int i=0; i<n; i++){ arr[i] = new Item(computer[i][0], computer[i][1], computer[i][2], 0); // Set ernings to negative, so we only take the profit sumCores += computer[i][0]; } Arrays.sort(arr); dp = new long[n+m+1][sumCores+1]; for (int i=0; i<=n+m; i++){ Arrays.fill(dp[i], (long)-1e19); } dp[0][0] = 0; for (int i=1; i<=n+m; i++){ for (int j=0; j<=sumCores; j++){ dp[i][j] = dp[i-1][j]; if (arr[i-1].t == 0){ if (j - arr[i-1].c >= 0){ dp[i][j] = Math.max(dp[i][j], dp[i-1][j - arr[i-1].c] - arr[i-1].earn); } }else{ if (j + arr[i-1].c <= sumCores){ dp[i][j] = Math.max(dp[i][j], dp[i-1][j + arr[i-1].c] + arr[i-1].earn); } } } } long ans = 0; for (int i=0; i<=sumCores; i++){ ans = Math.max(ans, dp[n+m][i]); } System.out.println(ans); } static class Item implements Comparable<Item>{ int c, f, earn, t; public Item(int c, int f, int earn, int t){ this.c = c; this.f = f; this.earn = earn; this.t = t; } public int compareTo(Item o){ if (o.f == this.f){ if (this.t == o.t){ return 0; } if (this.t == 0){ return 1; }else{ return -1; } } return Integer.compare(o.f, this.f); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...