/* -*- coding: utf-8 -*- * * 3389.cc: No.3389 k-Days Later - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ using ll = long long; /* global variables */ int ds[MAX_N]; ll dss[MAX_N + 1]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", ds + i); for (int i = 0; i < n; i++) dss[i + 1] = dss[i] + ds[i]; int qn; scanf("%d", &qn); while (qn--) { ll yi, ki; int mi, di; scanf("%lld%d%d%lld", &yi, &mi, &di, &ki); ll doy = dss[mi - 1] + (di - 1) + ki; ll ai = yi + doy / dss[n]; doy %= dss[n]; int bi = upper_bound(dss, dss + n + 1, doy) - dss - 1; int ci = doy - dss[bi]; printf("%lld %d %d\n", ai, bi + 1, ci + 1); } return 0; }