luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/TRETRAU #905

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Chi tiết bài tập - Luyện Code Online

https://oj.luyencode.net/problem/TRETRAU

tambl2004 commented 1 year ago

vẫn không đủ time, 8/14, mn sửa giùm code với, code java: import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); int[] cnt = new int[n + 1]; int[] firstDay = new int[n + 1]; Arrays.fill(firstDay, -1); for (int i = 0; i < d; i++) { int s = sc.nextInt(); int k = sc.nextInt(); int p = sc.nextInt(); int curDay = 0; for (int j = s; j <= n && curDay < p; j += k) { cnt[j]++; curDay++; if (firstDay[j] == -1) { firstDay[j] = i; } } } int maxCnt = -1; int ans = 0; for (int i = 1; i <= n; i++) { if (cnt[i] > maxCnt || (cnt[i] == maxCnt && firstDay[i] < firstDay[ans])) { maxCnt = cnt[i]; ans = i; } } System.out.println("Dung can hack dien dan " + ans + "."); } }