#include <iostream> #include <cstdint> #include <vector> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m; int a; uint64_t b, d, suma; vector<uint64_t> ile_urosnie; cin >> n; // ile rodzajow trawy cin >> m; // ile dni kosil for(int i = 0; i < n; i++) { cin >> a; ile_urosnie.push_back(a); } vector<uint64_t> pole(ile_urosnie); //wczytac dane b na dzien for(int i = 1; i <= m; i++) { suma = 0; cin >> d; cin >> b; for(int j = 0; j < n; j++) { if(pole[j] > b) { suma = suma + pole[j] - b; pole[j] = b; } pole[j] = pole[j] + ile_urosnie[j]; } cout << suma << "\n"; } 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 42 | #include <iostream> #include <cstdint> #include <vector> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m; int a; uint64_t b, d, suma; vector<uint64_t> ile_urosnie; cin >> n; // ile rodzajow trawy cin >> m; // ile dni kosil for(int i = 0; i < n; i++) { cin >> a; ile_urosnie.push_back(a); } vector<uint64_t> pole(ile_urosnie); //wczytac dane b na dzien for(int i = 1; i <= m; i++) { suma = 0; cin >> d; cin >> b; for(int j = 0; j < n; j++) { if(pole[j] > b) { suma = suma + pole[j] - b; pole[j] = b; } pole[j] = pole[j] + ile_urosnie[j]; } cout << suma << "\n"; } return 0; } |