Hej! Som rubriken lyder så har jag problem med en uppgift jag har i skolan.
Suttit och läst igenom den hundra tals gånger men kommer ändå inte fram till någon lösning.
Tänkte om de finns någon här som kan hjälpa mig på tråden
Tack på förhand!
Jag skriver uppgiften innanför html tagg så kanske man ser det lättare
Suttit och läst igenom den hundra tals gånger men kommer ändå inte fram till någon lösning.
Tänkte om de finns någon här som kan hjälpa mig på tråden
Tack på förhand!
Jag skriver uppgiften innanför html tagg så kanske man ser det lättare
HTML-kod:
Meera teaches a class of n students, and every day in her classroom is an adventure. Today it drawing day! The students are sitting around a round table, and they are numbered from 1 to n in the clockwise direction. This means that the students are numbered 1,2,3,...,n-1,n, and students 1 and n are sitting next to each other. After letting the students draw for a certain perdiof of time. Meera starts collecting their work to ensure she has the time to review all the drawings before the end of the day. However, some of her students are't finished drawing! Each student _i needs _ti extra minutes to complete their drawing. Meera collects the drawings squentially in the clockwise direction, starting with studen ID x, and it takes her exactly 1 minute to review each drawing. This means that student x gets 0 extra minutes to complete their drawinr, stund x + 1 gets 1 extra minute student x + 2 gets 2 extra minutes and so on. NOTE that Meera will still spend 1 minute for each student even if the drawing isn't ready. Given the values t1,t2,....,tN, help Meera choose the best possible X to start colleting drawings from, such that number of students able to complete their drawings in maximal. Then print x on a new line. if there are multiple such IDs, select the smallest one. INPUT FORMAT The first line contains a single positive integer, n, denoting the number of students in the class. The secound line containts n space-separated integers describing the respective amounts of time that each student needs to finish their drawins (i.e.,t1,t2,...,tn). CONSTRAINTS * 1<n<10*10*10*10*10 (Det ska vara 10 upphöjt med 5 men gick ej att skriva) *0<ti<n OUTPUT FORMAT Print an integer denoting the ID number, x, where Meera should start collecting the drawings such that a maximal number of students can complete their drawings. If there are multiple such IDs, sekect the smallest one. SAMPLE INPUT 3 1 0 0 SAMPLE OUTPUT 2 EXPLANATION Meera's class has n=3 students: 1.if x=1, the only two students will finish. The first student needs t1=1 extra minute to complete their drawing. if Meera starts collecting here, this student will never finish their drawing. Students 2 and 3s drawings are already finished, so their drawings are ready when she collects them in the secound and this minutes. 2.if x=2, then all three stundets will finish. The secound student needs t2=0 extra minutes, so the drawing is ready for Meera to collect. The next (third) student's drawing is also ready one minute later, as t3=0. Meera then proceeds ti the next (first) student, who needed t1= 1 extra minute. Because she already spent two minutes collecting the work of the other two students, the first stundent's drawing has already been completed for 2 - 1 = 1 minute. 3.if x=3, then all three students will finish. The third student needs t3 = 0 extra minutes, so the drawing is ready for Meera to collect. The next(first) student's drawing is also ready one minute laater, as t1=1 and 1 minute passed while Meera collected the third student's drawing. She then proceeds to the next (secound) student, whose drawing was already completed (as t2=0) Stating with student IDs x=2 or x=3 will result in a maximum number of competed drawings (i.e.,3) Because there are two equally valid aswers, we choose the smalled ID, 2, and print it as our answer. public class Solution { public static void main(String [] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ } }