Submission #74943597
Source Code Expand
import java.io.*;
import java.util.*;
public class Main {
static long[] x;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] nm = br.readLine().split(" ");
int n = Integer.parseInt(nm[0]);
int m = Integer.parseInt(nm[1]);
String[] dStr = br.readLine().split(" ");
int[] d = new int[n];
for(int i = 0; i < n; i++) d[i] = Integer.parseInt(dStr[i]);
x = new long[m];
if(m > 0) {
String[] xStr = br.readLine().split(" ");
for(int i = 0; i < m; i++) x[i] = Long.parseLong(xStr[i]);
Arrays.sort(x);
}
int OFFSET = 50000;
int SIZE = 100001;
boolean[] dp = new boolean[SIZE];
dp[OFFSET] = true;
for(int i = 0; i < n; i++) {
boolean[] next = new boolean[SIZE];
for(int pos = 0; pos < SIZE; pos++) {
if(!dp[pos]) continue;
// skip
next[pos] = true;
// take
int newPos = pos + d[i];
if(newPos >= 0 && newPos < SIZE) {
long a = pos - OFFSET;
long b = newPos - OFFSET;
if(!collision(a, b)) {
next[newPos] = true;
}
}
}
dp = next;
}
long ans = Long.MIN_VALUE;
for(int i = 0; i < SIZE; i++) {
if(dp[i]) {
ans = Math.max(ans, i - OFFSET);
}
}
System.out.println(ans);
}
static boolean collision(long a, long b) {
long l = Math.min(a, b);
long r = Math.max(a, b);
int idx = lowerBound(x, l);
return idx < x.length && x[idx] <= r;
}
static int lowerBound(long[] a, long x) {
int l = 0, r = a.length;
while(l < r) {
int mid = (l + r) / 2;
if(a[mid] < x) l = mid + 1;
else r = mid;
}
return l;
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - A Walk and Barricades |
| User | KrishnaPriya_16 |
| Language | Java24 (OpenJDK 24.0.2) |
| Score | 0 |
| Code Size | 2355 Byte |
| Status | TLE |
| Exec Time | > 2000 ms |
| Memory | 73764 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 466 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample01.txt, sample02.txt, sample03.txt, sample04.txt, sample05.txt |
| All | sample01.txt, sample02.txt, sample03.txt, sample04.txt, sample05.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| in01.txt | AC | 38 ms | 38632 KiB |
| in02.txt | AC | 51 ms | 39796 KiB |
| in03.txt | AC | 56 ms | 39968 KiB |
| in04.txt | AC | 55 ms | 39472 KiB |
| in05.txt | AC | 45 ms | 39664 KiB |
| in06.txt | AC | 54 ms | 39412 KiB |
| in07.txt | AC | 56 ms | 39988 KiB |
| in08.txt | AC | 42 ms | 39520 KiB |
| in09.txt | AC | 42 ms | 39140 KiB |
| in10.txt | AC | 48 ms | 40368 KiB |
| in11.txt | AC | 60 ms | 49348 KiB |
| in12.txt | AC | 97 ms | 56612 KiB |
| in13.txt | AC | 43 ms | 39120 KiB |
| in14.txt | AC | 55 ms | 39504 KiB |
| in15.txt | AC | 58 ms | 40752 KiB |
| in16.txt | AC | 51 ms | 41340 KiB |
| in17.txt | AC | 55 ms | 39888 KiB |
| in18.txt | AC | 42 ms | 39288 KiB |
| in19.txt | AC | 58 ms | 40072 KiB |
| in20.txt | AC | 44 ms | 39572 KiB |
| in21.txt | AC | 43 ms | 38976 KiB |
| in22.txt | AC | 56 ms | 39640 KiB |
| in23.txt | AC | 53 ms | 41012 KiB |
| in24.txt | AC | 52 ms | 41828 KiB |
| in25.txt | AC | 47 ms | 40276 KiB |
| in26.txt | AC | 47 ms | 40456 KiB |
| in27.txt | AC | 56 ms | 40352 KiB |
| in28.txt | AC | 58 ms | 40464 KiB |
| in29.txt | AC | 53 ms | 40292 KiB |
| in30.txt | AC | 59 ms | 40544 KiB |
| in31.txt | TLE | > 2000 ms | 36444 KiB |
| in32.txt | TLE | > 2000 ms | 36412 KiB |
| in33.txt | AC | 592 ms | 73764 KiB |
| in34.txt | AC | 642 ms | 71312 KiB |
| in35.txt | TLE | > 2000 ms | 38624 KiB |
| in36.txt | TLE | > 2000 ms | 38664 KiB |
| in37.txt | TLE | > 2000 ms | 35964 KiB |
| in38.txt | TLE | > 2000 ms | 46452 KiB |
| in39.txt | TLE | > 2000 ms | 50772 KiB |
| in40.txt | TLE | > 2000 ms | 50620 KiB |
| in41.txt | TLE | > 2000 ms | 46720 KiB |
| in42.txt | TLE | > 2000 ms | 53192 KiB |
| in43.txt | TLE | > 2000 ms | 48336 KiB |
| in44.txt | TLE | > 2000 ms | 48152 KiB |
| in45.txt | TLE | > 2000 ms | 38108 KiB |
| in46.txt | TLE | > 2000 ms | 48848 KiB |
| in47.txt | TLE | > 2000 ms | 51380 KiB |
| sample01.txt | AC | 57 ms | 39700 KiB |
| sample02.txt | AC | 50 ms | 39456 KiB |
| sample03.txt | AC | 60 ms | 40884 KiB |
| sample04.txt | AC | 66 ms | 42296 KiB |
| sample05.txt | AC | 42 ms | 38736 KiB |