#include <iostream>
using namespace std;
int prio_map(int prio_min, int prio_max, int weight_beg, int weight_end, int prio)
{
int temp;
temp = weight_beg - (prio - prio_min)*(weight_beg - weight_end +1)/(prio_max - prio_min + 1);
return temp;
}
int main() {
cout << "Hello world! - cpp.jsrun.net." << endl;
int a[5] = {50,30,10,10};
int PRIO_RT_MAX = sizeof(a)/sizeof(a[0]);
int prio_min = 0;
int prio_max = 0;
int weight_beg = 40;
int weight_end = 40;
int weight_level = (40 - 21 + 1)/PRIO_RT_MAX;
int weight = 0;
cout<< PRIO_RT_MAX <<endl;
cout<< weight_level <<endl;
int prio =0;
weight_level = (40 - 21 + 1)/PRIO_RT_MAX;
for(int i = 0; i < PRIO_RT_MAX; i++) {
prio_max += (a[i] );
weight_end -= (weight_level +1);
if (prio <= prio_max - 1)
break;
weight_beg -= (weight_level +1);
prio_min += (a[i] );
}
prio_max -=1;
weight_end += 1;
cout << "------" << prio << "------"<< endl;
cout<< "prio_min "<< prio_min<< " prio_max "<<prio_max<<endl;
cout <<"weight_beg "<<weight_beg<<" weight_end "<<weight_end<<endl;
weight = prio_map(prio_min, prio_max, weight_beg, weight_end, prio);
cout<<weight<<endl;
return 0;
}