fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int n, m;
  9. cin >> n >> m;
  10.  
  11. long long a[200005], pref[200006], b[200005];
  12.  
  13. pref[0] = 0;
  14. for (int i = 1; i <= n; i++) {
  15. cin >> a[i];
  16. pref[i] = pref[i - 1] + a[i];
  17. }
  18. for (int j = 0; j < m; j++) cin >> b[j];
  19.  
  20. int f = 1;
  21. for (int j = 0; j < m; j++) {
  22. while (f <= n && pref[f] < b[j]) f++;
  23. long long k = b[j] - pref[f - 1];
  24. cout << f << " " << k << "\n";
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 5584KB
stdin
5 2
1 2 3 4 5
stdout
1 0
1 0