Skip to content

Instantly share code, notes, and snippets.

@overnew
Created October 11, 2020 14:09
Show Gist options
  • Save overnew/c54e48d17126c405307b21319f75c14e to your computer and use it in GitHub Desktop.
Save overnew/c54e48d17126c405307b21319f75c14e to your computer and use it in GitHub Desktop.
FESTIVAL 정답 코드
#include<iostream>
using namespace std;
int borrowCost[1000];
int main(){
int numTest;
int maxDays,numTeam;
double minCost;
double divResult;
cin>>numTest;
for(int i=0; i <numTest ; ++i){
cin>>maxDays>>numTeam;
for(int j=0; j<maxDays ; ++j)
cin>>borrowCost[j];
minCost = 100; //모든 비용은 100이하이므로 100이 평군의 최대값
for(int j = numTeam; j<=maxDays ; ++j){
double sum = 0;
for(int k=0; k<j ; ++k)
sum += borrowCost[k]; //일단은 0~j-1까지 더해둠
divResult = sum/j;
minCost = minCost < divResult ? minCost: divResult;
for(int starIdx=j; starIdx< maxDays ; ++starIdx){
sum -= borrowCost[starIdx-j]; //가장 앞의 수를 빼주고
sum += borrowCost[starIdx]; //그 뒤 차례의 수를 더해줌
divResult = sum/j;
minCost = minCost < divResult ? minCost: divResult;
}
}
printf("%.11f\n",minCost);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment