Alex_tz307

Classic - Level 2

Oct 30th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("text.in");
  7. ofstream fout("text.out");
  8.  
  9. int32_t main() {
  10.     fin.sync_with_stdio(false);
  11.     fout.sync_with_stdio(false);
  12.     fin.tie(nullptr);
  13.     fout.tie(nullptr);
  14.     int N;
  15.     fin >> N;
  16.     vector < int > a(N + 1);
  17.     for(int i = 1; i <= N; ++i) {
  18.         fin >> a[i];
  19.         a[i] += a[i - 1];
  20.     }
  21.     int M;
  22.     fin >> M;
  23.     fout << M << '\n';
  24.     while(M--) {
  25.         int id, lg;
  26.         fin >> id >> lg;
  27.         fout << id << ' ';
  28.         int mn = INT_MAX, ans = 1;
  29.         for(int i = 1; i <= N; ++i) {
  30.             int j = i + lg - 1;
  31.             if(j > N)
  32.                 break;
  33.             int sum = a[j] - a[i - 1];
  34.             if(sum < mn) {
  35.                 ans = i;
  36.                 mn = sum;
  37.             }
  38.         }
  39.         fout << ans - 1 << '\n';
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment