#include2.2 AcWing-800:数组元素的目标和 1. 问题描述 2. 问题解决#include #include using namespace std; const int N = 1e5 + 10; int a[N], s[N]; int n; int res = 0; int main() { scanf("%d", &n); for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]); for(int i = 0, j = 0; i < n; i++) { s[a[i]]++; while(s[a[i]] > 1) { s[a[j]]--; j++; } res = max(res, i - j + 1); } cout << res << endl; return 0; }
#include#include #include using namespace std; const int N = 1e5 + 10; int a[N], b[N]; int n, m, x; int main() { scanf("%d%d%d", &n, &m, &x); for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]); for (int j = 0; j < m; j ++ ) scanf("%d", &b[j]); for (int i = 0, j = m-1; i < n; i++) { while (a[i] + b[j] > x && j >= 0) j--; if(a[i] + b[j] == x) { cout << i << ' ' << j << endl; break;} } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)