Thứ Hai, 5 tháng 11, 2012

Problem Two Bags of Potatoes

Link: http://codeforces.com/problemset/problem/239/A


A. Two Bags of Potatoes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Valera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second —y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater than n, and, secondly, was divisible by k.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
Input
The first line of input contains three integers ykn (1 ≤ y, k, n ≤ 109;   ≤ 105).
Output
Print the list of whitespace-separated integers — all possible values of x in ascending order. You should print each possible value of x exactly once.
If there are no such values of x print a single integer -1.
Sample test(s)
input
10 1 10
output
-1
input
10 6 40
output
2 8 14 20 26 


Algorithm: Implement

code:


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<utility>
#include<map>
#include<list>
#include<queue>
#include<stack>

using namespace std;

vector<int> V;
map<int,int> M;
set<int> S;


int main()
{
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
int k,y,n;

cin >> y >> k >> n;

bool isok = true;
for(int i=1; i*k<=n;i++)
{
if(i*k-y>=1 && i*k<=n)
{
isok= false;
cout << i*k-y << " ";
}
}
if(isok)
cout << -1 << endl;
return 0;
}




Không có nhận xét nào:

Đăng nhận xét