Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions src/jinu/week21/Week21_18808.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package jinu.week21;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Week21_18808 {

static int noteBook[][];

static List<int[][]> stickers;

public static void main(String[] args) throws Exception {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());

noteBook = new int[N][M];

int K = Integer.parseInt(st.nextToken());

stickers = new ArrayList<>();

for(int i = 0;i < K; i++){
st = new StringTokenizer(br.readLine());

int R = Integer.parseInt(st.nextToken());
int C = Integer.parseInt(st.nextToken());

int tmp[][] = new int[R][C];

for(int r = 0; r<R; r++){
st = new StringTokenizer(br.readLine());
for(int j = 0; j<C;j++){
tmp[r][j] = Integer.parseInt(st.nextToken());
}
}

stickers.add(tmp);
}

// print(noteBook);
// System.out.println("---------------------");



for(int sticker[][] : stickers){

int applySticker[][] = sticker;

boolean next = false;

for(int k =0 ;k < 4; k++){

for(int i =0 ;i< N;i++){
for(int j =0 ; j<M;j++){

if(next){
break;
}

if(canApply(noteBook, applySticker, i, j)){
apply(noteBook, applySticker, i, j);
next = true;
}

}
}

if(next){
break;
}

applySticker = turnRight(applySticker);
}
// print(noteBook);
// System.out.println("---------------------------");
}

// print(noteBook);

System.out.println(countOne(noteBook));




}

public static boolean canApply(int [][]noteBook, int applySticker[][], int i, int j){
for(int y = i; y < i + applySticker.length; y++){
for(int x = j; x < j + applySticker[0].length; x++){

if(y >= noteBook.length || x >= noteBook[0].length){
return false;
}

if(noteBook[y][x]==1 && applySticker[y-i][x-j] == 1){
return false;
}
}
}

return true;
}

public static void apply(int [][]noteBook, int applySticker[][], int i, int j){

for(int y = i; y < i + applySticker.length; y++){
for(int x = j; x < j + applySticker[0].length; x++){

if(noteBook[y][x]==0 && applySticker[y-i][x-j]==1){
noteBook[y][x] = applySticker[y-i][x-j];
}
}
}
}

public static int[][] turnRight(int [][]applySticker){

int tmpApplySticker[][] = new int[applySticker[0].length][applySticker.length];

for(int i = 0; i <applySticker.length; i++){
for(int j =0;j<applySticker[0].length; j++){
tmpApplySticker[j][applySticker.length-1-i] = applySticker[i][j];
}
}

return tmpApplySticker;
}

public static void print(int noteBook[][]){
for(int i=0;i<noteBook.length; i++){
for(int j=0;j<noteBook[0].length; j++){
System.out.print(noteBook[i][j]+" ");
}
System.out.println();
}
}

public static int countOne(int noteBook[][]){

int count = 0;

for(int i=0;i<noteBook.length; i++){
for(int j=0;j<noteBook[0].length; j++){
if(noteBook[i][j]==1){
count++;
}
}
}

return count;
}

}
83 changes: 83 additions & 0 deletions src/jinu/week21/Week21_2461.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package jinu.week21;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Week21_2461 {

static List<Integer> abilities[];

static class Node implements Comparable<Node>{
int index;
int ability;

public Node(int index, int ability){
this.index = index;
this.ability = ability;
}

public int compareTo(Node n){
return this.ability-n.ability;
}
}
public static void main(String[] args) throws Exception {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());

abilities = new List[N];
for(int i =0;i<N;i++){
st = new StringTokenizer(br.readLine());
abilities[i] = new ArrayList<>();
for(int j=0;j<M;j++){
abilities[i].add(Integer.parseInt(st.nextToken()));
}
Collections.sort(abilities[i]);
}

int []abilityIndex = new int[N];

Arrays.fill(abilityIndex, 0);

PriorityQueue<Node> pq = new PriorityQueue<>();

int max = Integer.MIN_VALUE;

for(int i=0;i<N;i++){
pq.add(new Node(i, abilities[i].get(abilityIndex[i])));
max = Math.max(max, abilities[i].get(abilityIndex[i]));
}

int minDiff = Integer.MAX_VALUE;

while(!pq.isEmpty()){

Node n = pq.poll();
minDiff = Math.min(minDiff, (max-n.ability));

// System.out.println("max: "+max);
// System.out.println("min: "+n.ability);

if(abilityIndex[n.index]<=M-2){
abilityIndex[n.index]++;
max = Math.max(max, abilities[n.index].get(abilityIndex[n.index]));
pq.add(new Node(n.index, abilities[n.index].get(abilityIndex[n.index])));
}
else{
break;
}
}

System.out.println(minDiff);
}

}
90 changes: 90 additions & 0 deletions src/jinu/week21/Week21_2515.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package jinu.week21;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Week21_2515 {

static class Painting implements Comparable<Painting>{

int height;
int cost;

public Painting(int height, int cost){
this.height = height;
this.cost = cost;
}

@Override
public int compareTo(Painting p){
return this.height - p.height;
}
}

static Painting[] paintings;
static int []limit, dp;
static int N,S;

public static void main(String[] args) throws Exception {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

N = Integer.parseInt(st.nextToken());
S = Integer.parseInt(st.nextToken());

paintings = new Painting[N];
dp = new int[N];
limit = new int[N];

for(int i=0;i<N;i++){
st = new StringTokenizer(br.readLine());
paintings[i] = new Painting(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
}

Arrays.sort(paintings);

dp[0] = paintings[0].cost;

for(int i=1;i<N;i++){
int findMaxHighIndex = binarySearch(i);
if(findMaxHighIndex > -1){
dp[i] = Math.max(dp[findMaxHighIndex]+paintings[i].cost, dp[i-1]);
}
else{
dp[i] = Math.max(dp[i-1], paintings[i].cost);
}
}

System.out.println(dp[N-1]);





}

static int binarySearch(int index){
int mid = 0;
int left = 0;
int right = index;

while(left<=right){
mid = (left+right)/2;

int diff = paintings[index].height - paintings[mid].height;

if(diff>=S){
left = mid+1;
}
else{
right = mid - 1;
}
}

return left - 1;
}

}