#include <iostream> using namespace std; int n, m; int v[500001]; //speed int h[500001]; //height int pday = 0; //day of previous koszenie int cday = 0; //day read from cin int dif = 0; //days since last koszenie int ch = 0; //height read from cin int csuma = 0; //suma from current koszenie int main(){ ios_base::sync_with_stdio(0); cin>>n>>m; for(int i =0; i<n; i++){ cin>>v[i]; } for(int i =0; i<m; i++){ // iterates throug koszenie cin>>cday>>ch; dif = cday-pday; pday = cday; csuma = 0; for(int j =0; j<n; j++){ // iterates through gatunki h[j]+=dif*v[j]; if(h[j]>ch){ //jest trawa nad kosiarka csuma+=h[j]-ch; h[j]=ch; } } cout<<csuma<<endl; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <iostream> using namespace std; int n, m; int v[500001]; //speed int h[500001]; //height int pday = 0; //day of previous koszenie int cday = 0; //day read from cin int dif = 0; //days since last koszenie int ch = 0; //height read from cin int csuma = 0; //suma from current koszenie int main(){ ios_base::sync_with_stdio(0); cin>>n>>m; for(int i =0; i<n; i++){ cin>>v[i]; } for(int i =0; i<m; i++){ // iterates throug koszenie cin>>cday>>ch; dif = cday-pday; pday = cday; csuma = 0; for(int j =0; j<n; j++){ // iterates through gatunki h[j]+=dif*v[j]; if(h[j]>ch){ //jest trawa nad kosiarka csuma+=h[j]-ch; h[j]=ch; } } cout<<csuma<<endl; } return 0; } |